- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

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