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