ufl.hpp

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

Generated on 6 Feb 2012 for Vol by  doxygen 1.6.1