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