00001
00002
00003 #ifndef __UFL_HPP__
00004 #define __UFL_HPP__
00005
00006 #include <cstdio>
00007 #include <cfloat>
00008 #include <cstring>
00009 #include <string>
00010
00011 #include "VolVolume.hpp"
00012
00013
00014 class UFL_parms {
00015 public:
00016 std::string fdata;
00017 std::string dualfile;
00018 std::string dual_savefile;
00019 std::string int_savefile;
00020 int h_iter;
00021
00022
00023 UFL_parms(const char* filename);
00024 ~UFL_parms() {}
00025 };
00026
00027
00028
00029 class UFL : public VOL_user_hooks {
00030 public:
00031
00032
00033 int compute_rc(const VOL_dvector& u, VOL_dvector& rc);
00034
00035 int solve_subproblem(const VOL_dvector& u, const VOL_dvector& rc,
00036 double& lcost, VOL_dvector& x, VOL_dvector&v,
00037 double& pcost);
00038
00039
00040 int heuristics(const VOL_problem& p,
00041 const VOL_dvector& x, double& heur_val);
00042
00043
00044 public:
00045 VOL_dvector fcost;
00046 VOL_dvector dist;
00047 VOL_dvector fix;
00048
00049 int ncust, nloc;
00050 VOL_ivector ix;
00051 double icost;
00052 public:
00053 UFL() : icost(DBL_MAX) {}
00054 virtual ~UFL() {}
00055 };
00056
00057
00058
00059
00060
00061
00062
00063 UFL_parms::UFL_parms(const char *filename) :
00064 fdata(""),
00065 h_iter(10)
00066 {
00067 char s[500];
00068 FILE * file = fopen(filename, "r");
00069 if (!file) {
00070 printf("Failure to open ufl datafile: %s\n ", filename);
00071 abort();
00072 }
00073
00074 while (fgets(s, 500, file)) {
00075 const int len = strlen(s) - 1;
00076 if (s[len] == '\n')
00077 s[len] = 0;
00078 std::string ss;
00079 ss = s;
00080
00081 if (ss.find("fdata") == 0) {
00082 int j = ss.find("=");
00083 int j1 = ss.length() - j + 1;
00084 fdata = ss.substr(j+1, j1);
00085
00086 } else if (ss.find("dualfile") == 0) {
00087 int j = ss.find("=");
00088 int j1 = ss.length() - j + 1;
00089 dualfile = ss.substr(j+1, j1);
00090
00091 } else if (ss.find("dual_savefile") == 0) {
00092 int j = ss.find("=");
00093 int j1 = ss.length() - j + 1;
00094 dual_savefile = ss.substr(j+1, j1);
00095
00096 } else if (ss.find("int_savefile") == 0) {
00097 int j = ss.find("=");
00098 int j1 = ss.length() - j + 1;
00099 int_savefile = ss.substr(j+1, j1);
00100
00101 } else if (ss.find("h_iter") == 0) {
00102 int i = ss.find("=");
00103 h_iter = atoi(&s[i+1]);
00104 }
00105 }
00106 fclose(file);
00107 }
00108
00109 #endif