00001 #include<LEDA/list.h>
00002 #include<scil/cons.h>
00003 #include<scil/cons_obj.h>
00004 #include<scil/var_obj.h>
00005 #include<scil/subproblem.h>
00006 #include<scil/sym_constraint.h>
00007 #include<scil/ilp_problem.h>
00008 #include<scil/primal_heur.h>
00009 #include<scil/row.h>
00010 #include<scil/solution.h>
00011
00012 void subproblem::add_sym_constraint (sym_constraint * c)
00013 {
00014 cout<<"Warning: No local symbolic constaints allowed\n";
00015 sym_constraints.append (c);
00016 }
00017
00018 subproblem::subproblem(ILP_Problem* IP_) : GM(*IP_) {
00019 };
00020
00021 const
00022 string& subproblem::configuration(const string& s) const {
00023 return GM.configuration(s);
00024 };
00025
00026 string& subproblem::configuration(const string& s) {
00027 return GM.configuration(s);
00028 };
00029
00030 void
00031 subproblem::add_basic_constraint (cons_obj * c, Activation a = Static)
00032 {
00033 if(!GM.optimization_started()) {
00034 GM.add_basic_constraint(c, a);
00035 return;
00036 };
00037
00038 c->init();
00039
00040
00041
00042 EKKCut Cut;
00043 Cut.lowerBound=c->lower_bound();
00044 Cut.upperBound=c->upper_bound();
00045 Cut.numberElements=c->non_zeros;
00046 Cut.variable=c->rows;
00047 Cut.coefficient=c->coeffs;
00048 Cut.cutsOffSolution = 1;
00049 Cut.localCut=0;
00050 Cut.doNotDelete= 1;
00051 Cut.dummy=1;
00052 Cut.extraInfo=28;
00053 Cuts->cut[Cuts->numberCuts]=Cut;
00054 Cuts->numberCuts++;
00055 };
00056
00057 cons
00058 subproblem::add_basic_constraint (cons_sense s, double rhs,
00059 Activation a = Static)
00060 {
00061 cons_obj *
00062 c = new cons_obj (s, rhs);
00063 add_basic_constraint (c, a);
00064 return c;
00065 };
00066
00067 var
00068 subproblem::add_variable (double obj,
00069 double lBound, double uBound,
00070 Vartype t, Activation a = Static)
00071 {
00072 if(a!=Static)
00073 cout<<"Warning: No local variables allowed yet\n";
00074 return GM.add_variable(obj, lBound, uBound, t, a);
00075 };
00076
00077 void
00078 subproblem::add_variable (var_obj* v, Activation a = Static)
00079 {
00080 if(a!=Static)
00081 cout<<"Warning: No local variables allowed yet\n";
00082 GM.add_variable(v, a);
00083 }
00084
00085 bool
00086 subproblem::feasible () {
00087
00088 solution SOL;
00089
00090 double d;
00091 for(int i=0; i<GM.number_of_variables(); i++) {
00092 d=value(get_var(i));
00093 if(d>0.0001) {
00094 if(d<0.9999) return false;
00095 SOL.set_value(get_var(i),1);
00096 };
00097 };
00098
00099 return feasible(*this, SOL);
00100 }
00101
00102 bool
00103 subproblem::feasible (subproblem & S, solution& Sol)
00104 {
00105
00106 sym_constraint * s;
00107 forall (s, GM.sym_constraints)
00108 {
00109 if (s->feasible (Sol) == sym_constraint::infeasible_solution)
00110 return false;
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 return true;
00122 };
00123
00124 int
00125 subproblem::separate ()
00126 {
00127
00128
00129
00130
00131
00132 return separate (*this);
00133 };
00134
00135 int
00136 subproblem::separate (subproblem & S)
00137 {
00138 int t = 0;
00139
00140 sym_constraint *
00141 s;
00142 forall (s, GM.sym_constraints)
00143 {
00144 if (s->separate (S) == sym_constraint::constraint_found)
00145 t++;
00146 };
00147
00148
00149
00150
00151
00152
00153
00154
00155 return t;
00156 };
00157
00158 void subproblem::set_coefficient (var v, cons i, double d)
00159 {
00160
00161
00162
00163 };
00164
00165 var subproblem::get_var (int i)
00166 {
00167
00168 return nil;
00169
00170
00171 };
00172
00173 int subproblem::nVar () const
00174 {
00175
00176 return GM.number_of_variables();
00177 };
00178
00179 cons subproblem::get_cons (int i)
00180 {
00181
00182
00183 return nil;
00184
00185 };
00186
00187 int subproblem::ncons ()
00188 {
00189
00190
00191 return 1;
00192 };
00193
00194
00195 double subproblem::value (var v)
00196 {
00197
00198 if(v==nil) return 1;
00199
00200 if(v.index()==fixvar) return fixvalue;
00201
00202 return ekk_colsol(mipModel)[v.index()];
00203 };
00204
00205 double subproblem::value(row& r) {
00206 row_entry re;
00207 double d=0;
00208 forall(re, r) d+=re.coeff*value(re.Var);
00209 return d;
00210 };
00211
00212 double subproblem::lower_bound (var v)
00213 {
00214
00215 return 0;
00216 }
00217
00218
00219 double subproblem::upper_bound (var v)
00220 {
00221
00222 return 0;
00223 }
00224
00225 double subproblem::value (cons i, as_what as = as_is) {
00226
00227 if (i.cons_pointer () == nil)
00228 {
00229 cout << "nil basic constraint\n"; return 0;}
00230 double d = 0;
00231 if (as == as_is) return d;
00232 if ((as == as_max) && (GM.opt_sense () == Optsense_Max)) return d;
00233 if ((as == as_min) && (GM.opt_sense () == Optsense_Min)) return d;
00234 return -d;
00235 }
00236
00237
00238
00239 int subproblem::separate (subproblem &);
00240
00241 void subproblem::activate (subproblem & S)
00242 {
00243 sym_constraint * s;
00244
00245 forall (s, sym_constraints)
00246 {
00247 s->open_subproblem (S);
00248 }
00249 }
00250
00251 void subproblem::activate ()
00252 {
00253 activate (*this);
00254 };
00255
00256
00257 void subproblem::deactivate (subproblem & S)
00258 {
00259 sym_constraint * s;
00260 forall (s, sym_constraints)
00261 {
00262 s->close_subproblem (S);
00263 };
00264 };
00265
00266
00267 void subproblem::deactivate ()
00268 {
00269 deactivate (*this);
00270 if (GM.primal_heur != nil)
00271 GM.primal_heur->heuristic (*this);
00272 };
00273
00274 double subproblem::red_cost(var v) {
00275
00276 return 0;
00277 };