00001 #include<scip/objscip.h>
00002 #include<scil/scil.h>
00003 #include"scip_constraint_handler.h"
00004
00005 using namespace scip;
00006
00007 namespace SCIL {
00008
00010 SCIPConsHandler::SCIPConsHandler(subproblem* MYSub_) : ObjConshdlr("CH", "SCIP Constraint Handler", 1, 1, -1, 1, -1, 1, true) {
00011 MYSub=MYSub_;
00012 };
00013
00019 RETCODE SCIPConsHandler::scip_delete(
00020 SCIP* scip,
00021 CONSHDLR* conshdlr,
00022 CONSDATA** consdata
00023 )
00024 {
00025 if( !SCIPisTransformed(scip) )
00026 delete(*consdata)->sc;
00027 SCIPfreeBlockMemory(scip, consdata);
00028
00029 return SCIP_OKAY;
00030 }
00031
00033 RETCODE SCIPConsHandler::scip_trans(
00034 SCIP* scip,
00035 CONSHDLR* conshdlr,
00036 CONS* sourcecons,
00037 CONS** targetcons
00038 ) {
00039 CONSDATA* sourcedata;
00040 CONSDATA* targetdata;
00041 sourcedata=SCIPconsGetData( sourcecons );
00042 CHECK_OKAY( SCIPallocBlockMemory( scip, &targetdata) );
00043 targetdata->sc=sourcedata->sc;
00044 CHECK_OKAY( SCIPcreateCons( scip, targetcons, SCIPconsGetName(sourcecons), conshdlr, targetdata, SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons),
00045 SCIPconsIsEnforced(sourcecons), SCIPconsIsChecked(sourcecons), SCIPconsIsPropagated(sourcecons), SCIPconsIsLocal(sourcecons),
00046 SCIPconsIsModifiable(sourcecons), SCIPconsIsRemoveable(sourcecons) ));
00047 return SCIP_OKAY;
00048 };
00049
00050 RETCODE SCIPConsHandler::scip_initlp(
00051 SCIP* scip,
00052 CONSHDLR* conshdlr,
00053 CONS** conss,
00054 int nconss
00055 )
00056 {
00057 CONSDATA* consdata;
00058 cout<<"HIER\n";
00059 for(int i=0; i<nconss; i++) {
00060 consdata=SCIPconsGetData(conss[i]);
00061 consdata->sc->init(*MYSub);
00062 }
00063 cout<<"END\n";
00064 return SCIP_OKAY;
00065 }
00066
00084 RETCODE SCIPConsHandler::scip_sepa(
00085 SCIP* scip,
00086 CONSHDLR* conshdlr,
00087 CONS** conss,
00088 int nconss,
00089 int nusefulconss,
00090 RESULT* result
00091 )
00092 {
00093 assert(result != NULL);
00094
00095 *result = SCIP_DIDNOTFIND;
00096
00097 cout<<"SEPARATE\n";
00098
00099 sym_constraint* sc;
00100
00101 forall_sym_constraints(sc, *MYSub) {
00102 sc->primal_heuristic(*MYSub);
00103 };
00104
00105 forall_sym_constraints(sc, *MYSub) {
00106 if(sc->separate(*MYSub)==sym_constraint::constraint_found)
00107 *result = SCIP_SEPARATED;
00108 };
00109
00110 if(*result==SCIP_DIDNOTFIND) cout<<"NO CONSTRAINT ADDED\n";
00111
00112 return SCIP_OKAY;
00113 }
00114
00145 RETCODE SCIPConsHandler::scip_enfolp(
00146 SCIP* scip,
00147 CONSHDLR* conshdlr,
00148 CONS** conss,
00149 int nconss,
00150 int nusefulconss,
00151 RESULT* result
00152 ) {
00153 return scip_check(scip, conshdlr, conss, nconss, NULL, true, false, result);
00154 };
00155
00186 RETCODE SCIPConsHandler::scip_enfops(
00187 SCIP* scip,
00188 CONSHDLR* conshdlr,
00189 CONS** conss,
00190 int nconss,
00191 int nusefulconss,
00192 Bool objinfeasible,
00193 RESULT* result
00194 ) {
00195 return scip_check(scip, conshdlr, conss, nconss, NULL, true, false, result);
00196 };
00197
00219 RETCODE SCIPConsHandler::scip_check(
00220 SCIP* scip,
00221 CONSHDLR* conshdlr,
00222 CONS** conss,
00223 int nconss,
00224 SOL* sol,
00225 Bool checkintegrality,
00226 Bool checklprows,
00227 RESULT* result
00228 ) {
00229 solution ssol;
00230 var v;
00231 forall_variables(v, (*MYSub)) {
00232 ssol.set_value(v, SCIPgetSolVal(scip, sol,
00233 ((Variable_Data*) v.var_pointer()->DATA)->varP));
00234 }
00235
00236 sym_constraint* sc;
00237 bool b=true;
00238 forall_sym_constraints(sc, (*MYSub)) {
00239 if(sc->feasible(ssol)==sym_constraint::infeasible_solution) {
00240 b=false;
00241 };
00242 };
00243 if(b) *result=SCIP_FEASIBLE;
00244 else *result=SCIP_INFEASIBLE;
00245 return SCIP_OKAY;
00246 }
00247
00297 RETCODE SCIPConsHandler::scip_lock(
00298 SCIP* scip,
00299 CONSHDLR* conshdlr,
00300 CONS* cons,
00301 int nlockspos,
00302 int nlocksneg
00303 ) {
00304 VAR** vars=SCIPgetOrigVars(scip);
00305 int nvars=SCIPgetNOrigVars(scip);
00306 for(int i=0; i<nvars; i++) {
00307 SCIPvarLock(vars[i], nlockspos+nlocksneg, nlockspos+nlocksneg);
00308 }
00309 return SCIP_OKAY;
00310 };
00311
00335 RETCODE SCIPConsHandler::scip_unlock(
00336 SCIP* scip,
00337 CONSHDLR* conshdlr,
00338 CONS* cons,
00339 int nlockspos,
00340 int nlocksneg
00341 ) {
00342 VAR** vars=SCIPgetOrigVars(scip);
00343 int nvars=SCIPgetNOrigVars(scip);
00344 for(int i=0; i<nvars; i++) {
00345 SCIPvarUnlock(vars[i], nlockspos+nlocksneg, nlockspos+nlocksneg);
00346 }
00347
00348 return SCIP_OKAY;
00349 };
00350
00351 void SCIPConsHandler::addCons(SCIP* scip, sym_constraint* sc) {
00352 CONSDATA* consdata;
00353 CHECK_ABORT( SCIPallocBlockMemory(scip, &consdata));
00354 consdata->sc=sc;
00355 CONS* con;
00356 CHECK_ABORT( SCIPcreateCons(scip, &con, "D",
00357 ((ILP_Problem_Data*) MYSub->ILP->DATA)->conshdlr, consdata,
00358 true, true, true, true, true, true, true, false) );
00359 CHECK_ABORT( SCIPaddCons(scip,con) );
00360 CHECK_ABORT( SCIPreleaseCons(scip, &con) );
00361 };
00362
00363
00364 };