00001 #include<LEDA/map.h>
00002 #include<LEDA/list.h>
00003 #include<scil/global.h>
00004 #include<scil/var_obj.h>
00005 #include<scil/cons_obj.h>
00006 #include<scil/variable.h>
00007 #include<scil/aba_variable.h>
00008 #include<scil/aba_constraint.h>
00009 #include<scil/subproblem.h>
00010 #include<scil/ilp_problem.h>
00011 #include<scil/row.h>
00012
00013 using namespace SCIL;
00014
00015 ABA_SUB* ILP_Problem::firstSub() {
00016 if(lpsolverset!=-1) defaultLpSolver((LPSOLVER) lpsolverset);
00017
00018 myroot=new subproblem(this);
00019
00020 Coefficient co;
00021 forall(co, coeff_list) {
00022 myroot->set_coefficient(co.first(), co.second(), co.third());
00023 }
00024
00025 sym_constraint* c;
00026 forall(c, sym_constraints) {
00027 myroot->add_sym_constraint(c);
00028 }
00029
00030 return myroot;
00031 };
00032
00033 const
00034 LEDA::string& ILP_Problem::configuration(const LEDA::string& s) const {
00035 return ConfMap[s];
00036 };
00037
00038 LEDA::string& ILP_Problem::configuration(const LEDA::string& s) {
00039 return ConfMap[s];
00040 };
00041
00042 void ILP_Problem::read_configuration_file(LEDA::string s) {
00043 ifstream ifs(s);
00044
00045 LEDA::string s1, s2;
00046 while(!ifs.eof()) {
00047 if(ifs.peek()=='#') s2.read_line(ifs); else {
00048 ifs >> s1;
00049 ifs >> s2;
00050 configuration(s1)=s2;
00051 }
00052 }
00053 };
00054
00056
00061 ILP_Problem::ILP_Problem (Optsense optSense, bool price) :
00062 ABA_MASTER ("none", true, price, (optSense == Optsense_Min ? ABA_OPTSENSE::Min :
00063 ABA_OPTSENSE::Max))
00064 {
00065 os = optSense;
00066 ChangeToCompiledLpSolver ();
00067 ABA_BUFFER < ABA_VARIABLE * >variables (this, 0);
00068 ABA_BUFFER < ABA_CONSTRAINT * >temp (this, 0);
00069 ABA_BUFFER < ABA_CONSTRAINT * >constraints (this, 0);
00070 initializePools (constraints, temp, variables,
00071 minimal_size, minimal_size, true);
00072 conPool ()->increase (minimal_size);
00073 cutPool ()->increase (minimal_size);
00074 nvars = 0;
00075 nconss = 0;
00076 primal_heur = 0;
00077 };
00078
00079
00081
00083 ILP_Problem::~ILP_Problem () {
00084 };
00085
00086
00087 void ILP_Problem::initialize_Optimization ()
00088 {};
00089
00090
00091 void ILP_Problem::initializeParameters ()
00092 {
00093
00094 readParameters (".abacus");
00095
00096 };
00097
00098 var ILP_Problem::add_variable (double obj, double lBound, double uBound,
00099 Vartype t, Activation a)
00100 {
00101 ABA_VARTYPE::TYPE type = ABA_VARTYPE::Continuous;
00102 if (t == Vartype_Integer)
00103 {
00104 if ((lBound == 0) && (uBound == 1))
00105 type = ABA_VARTYPE::Binary;
00106 else
00107 type = ABA_VARTYPE::Integer;
00108 }
00109 if (nvars == varPool ()->size ())
00110 varPool ()->increase (2 * nvars);
00111
00112 var_obj * v = new var_obj (obj, lBound, uBound, t);
00113 return add_variable (v, a);
00114 };
00115
00116
00117 var ILP_Problem::add_variable (var_obj * v, Activation a)
00118 {
00119 v->init (*this, nvars, a);
00120 varPool ()->insert (v->AVar ());
00121 nvars++;
00122 return v;
00123 };
00124
00125 void ILP_Problem::updateBestSolution (solution& Sol_)
00126 {
00127 Sol=Sol_;
00128 }
00129
00130 cons
00131 ILP_Problem::add_basic_constraint (cons_obj * c, Activation a)
00132 {
00133 c->init (*this, nconss, a);
00134 nconss++;
00135 if (conPool ()->number () == conPool ()->size ())
00136 conPool ()->increase (2 * conPool ()->size ());
00137 conPool ()->insert (c->Acons ());
00138 return c;
00139 };
00140
00141
00142 cons ILP_Problem::add_basic_constraint(cons_sense s, double r, Activation a) {
00143
00144
00145
00146 cons_obj* I=new cons_obj();
00147 I->set_sense(s);
00148 I->set_rhs(r);
00149 add_basic_constraint(I, a);
00150 return I;
00151 }
00152
00153 void ILP_Problem::add_sym_constraint(sym_constraint* c) {
00154
00155 sym_constraints.append(c);
00156 }
00157
00158 void ILP_Problem::set_coefficient(var v, cons i, double d) {
00159
00160
00161 coeff_list.append(Coefficient(v,i,d));
00162 };
00163
00164 void ILP_Problem::set_primal_heuristic(primal_heuristic* P) {
00165
00166 primal_heur=P;
00167 };
00168
00169 void ILP_Problem::optimize() {
00170
00171 ABA_MASTER::optimize();
00172 };
00173
00174
00175 double ILP_Problem::get_solution(var v) {
00176
00177 return Sol.value(v);
00178 }
00179
00180 double ILP_Problem::get_solution(row& r) {
00181 row_entry re;
00182 double d=0;
00183 forall(re, r) d+=re.coeff*get_solution(re.Var);
00184 return d;
00185 };