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