ufl.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef __UFL_HPP__
4 #define __UFL_HPP__
5 
6 #include <cstdio>
7 #include <cfloat>
8 #include <string>
9 
10 #include "VolVolume.hpp"
11 
12 // parameters controlled by the user
13 class UFL_parms {
14 public:
15  std::string fdata; // file with the data
16  std::string dualfile; // file with an initial dual solution
17  std::string dual_savefile; // file to save final dual solution
18  std::string int_savefile; // file to save primal integer solution
19  int h_iter; // number of times that the primal heuristic will be run
20  // after termination of the volume algorithm
21 
22  UFL_parms(const char* filename);
24 };
25 
26 
27 
28 class UFL : public VOL_user_hooks {
29 public:
30  // for all hooks: return value of -1 means that volume should quit
31  // compute reduced costs
32  int compute_rc(const VOL_dvector& u, VOL_dvector& rc);
33  // solve relaxed problem
34  int solve_subproblem(const VOL_dvector& u, const VOL_dvector& rc,
35  double& lcost, VOL_dvector& x, VOL_dvector&v,
36  double& pcost);
37  // primal heuristic
38  // return DBL_MAX in heur_val if feas sol wasn't/was found
39  int heuristics(const VOL_problem& p,
40  const VOL_dvector& x, double& heur_val);
41 
42  // original data for uncapacitated facility location
43 public:
44  VOL_dvector fcost; // cost for opening facilities
45  VOL_dvector dist; // cost for connecting a customer to a facility
46  VOL_dvector fix; // vector saying if some variables should be fixed
47  // if fix=-1 nothing is fixed
48  int ncust, nloc; // number of customers, number of locations
49  VOL_ivector ix; // best integer feasible solution so far
50  double icost; // value of best integer feasible solution
51 public:
52  UFL() : icost(DBL_MAX) {}
53  virtual ~UFL() {}
54 };
55 
56 //#############################################################################
57 //######## Member functions #########################################
58 //#############################################################################
59 
60 //****** UFL_parms
61 // reading parameters specific to facility location
62 UFL_parms::UFL_parms(const char *filename) :
63  fdata(""),
64  h_iter(10)
65 {
66  char s[500];
67  FILE * file = fopen(filename, "r");
68  if (!file) {
69  printf("Failure to open ufl datafile: %s\n ", filename);
70  abort();
71  }
72 
73  while (fgets(s, 500, file)) {
74  const int len = strlen(s) - 1;
75  if (s[len] == '\n')
76  s[len] = 0;
77  std::string ss;
78  ss = s;
79 
80  if (ss.find("fdata") == 0) {
81  int j = ss.find("=");
82  int j1 = ss.length() - j + 1;
83  fdata = ss.substr(j+1, j1);
84 
85  } else if (ss.find("dualfile") == 0) {
86  int j = ss.find("=");
87  int j1 = ss.length() - j + 1;
88  dualfile = ss.substr(j+1, j1);
89 
90  } else if (ss.find("dual_savefile") == 0) {
91  int j = ss.find("=");
92  int j1 = ss.length() - j + 1;
93  dual_savefile = ss.substr(j+1, j1);
94 
95  } else if (ss.find("int_savefile") == 0) {
96  int j = ss.find("=");
97  int j1 = ss.length() - j + 1;
98  int_savefile = ss.substr(j+1, j1);
99 
100  } else if (ss.find("h_iter") == 0) {
101  int i = ss.find("=");
102  h_iter = atoi(&s[i+1]);
103  }
104  }
105  fclose(file);
106 }
107 
108 #endif
~UFL_parms()
Definition: ufl.hpp:23
int nloc
Definition: ufl.hpp:48
std::string int_savefile
Definition: ufl.hpp:18
VOL_dvector fcost
Definition: ufl.hpp:44
vector of ints.
Definition: VolVolume.hpp:237
std::string fdata
Definition: ufl.hpp:15
VOL_ivector ix
Definition: ufl.hpp:49
UFL()
Definition: ufl.hpp:52
VOL_dvector fix
Definition: ufl.hpp:46
std::string dualfile
Definition: ufl.hpp:16
vector of doubles.
Definition: VolVolume.hpp:143
This class holds every data for the Volume Algorithm and its solve method must be invoked to solve th...
Definition: VolVolume.hpp:600
int h_iter
Definition: ufl.hpp:19
std::string dual_savefile
Definition: ufl.hpp:17
virtual ~UFL()
Definition: ufl.hpp:53
UFL_parms(const char *filename)
Definition: ufl.hpp:62
double icost
Definition: ufl.hpp:50
The user hooks should be overridden by the user to provide the problem specific routines for the volu...
Definition: VolVolume.hpp:558
Definition: ufl.hpp:28
VOL_dvector dist
Definition: ufl.hpp:45