ufl.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
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 // parameters controlled by the user
00014 class UFL_parms {
00015 public:
00016   std::string fdata; // file with the data
00017   std::string dualfile; // file with an initial dual solution
00018   std::string dual_savefile; // file to save final dual solution
00019   std::string int_savefile; // file to save primal integer solution
00020   int h_iter; // number of times that the primal heuristic will be run
00021   // after termination of the volume algorithm
00022    
00023   UFL_parms(const char* filename);
00024   ~UFL_parms() {}
00025 };
00026 
00027 
00028 
00029 class UFL : public VOL_user_hooks {
00030 public:
00031   // for all hooks: return value of -1 means that volume should quit
00032   // compute reduced costs
00033    int compute_rc(const VOL_dvector& u, VOL_dvector& rc);
00034   // solve relaxed problem
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   // primal heuristic
00039   // return DBL_MAX in heur_val if feas sol wasn't/was found 
00040    int heuristics(const VOL_problem& p, 
00041                   const VOL_dvector& x, double& heur_val);
00042 
00043   // original data for uncapacitated facility location
00044 public: 
00045   VOL_dvector fcost; // cost for opening facilities
00046   VOL_dvector dist; // cost for connecting a customer to a facility
00047   VOL_dvector fix; // vector saying if some variables should be fixed
00048   // if fix=-1 nothing is fixed
00049   int ncust, nloc; // number of customers, number of locations
00050   VOL_ivector ix;   // best integer feasible solution so far
00051   double      icost;  // value of best integer feasible solution 
00052 public:
00053   UFL() : icost(DBL_MAX) {}
00054   virtual ~UFL() {}  
00055 };
00056 
00057 //#############################################################################
00058 //########  Member functions          #########################################
00059 //#############################################################################
00060 
00061 //****** UFL_parms
00062 // reading parameters specific to facility location
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

Generated on Tue Jun 14 23:14:05 2011 for Cbc by  doxygen 1.4.7