#define EPS 0.0000001 #include #include #include ILOSTLBEGIN typedef IloArray NumArray2; IloInt numCuts = 0; ILOCUTCALLBACK3(lotSizingCuts, NumArray2, D, IloNumVarArray, product, IloNumVarArray, setup) { try{ IloEnv env = getEnv(); IloInt NT = product.getSize(); for (int t = 0; t < NT; t++){ IloExpr lhs(env); IloNum value = 0; for (int s = 0; s <= t; s++){ if (getValue(product[s]) > D[s][t]*getValue(setup[s]) + EPS){ lhs += D[s][t] * setup[s]; value += D[s][t] * getValue(setup[s]); } else{ lhs += product[s]; value += getValue(product[s]); } } if (value < D[0][t] - EPS){ add(lhs >= D[0][t]); numCuts ++; env.out()<= "<= rhs ); lhs.end(); rhs.end(); } for(t = 0; t < NT; t++) model.add( product[t] <= D[t][NT-1]*setup[t] ); IloCplex cplex(model); cplex.use(lotSizingCuts(env,D,product,setup)); cplex.exportModel("ls-model.lp"); IloNum eps = cplex.getParam(IloCplex::EpInt); ofstream logfile("cplex.log"); cplex.setOut(logfile); cplex.setWarning(logfile); cplex.setParam(IloCplex::TiLim, 1800); cplex.setParam(IloCplex::TreLim, 100); cplex.setParam(IloCplex::NodeLim, 1000000); cplex.setParam(IloCplex::MIPDisplay, 2); cplex.setParam(IloCplex::HeurFreq, -1); cplex.setParam(IloCplex::PreInd,0); cplex.setParam(IloCplex::Covers,-1); cplex.setParam(IloCplex::Cliques,-1); cplex.setParam(IloCplex::FlowCovers,-1); cplex.setParam(IloCplex::GUBCovers,-1); cplex.setParam(IloCplex::FracCuts,-1); cplex.setParam(IloCplex::MIRCuts,-1); cplex.setParam(IloCplex::FlowPaths,-1); cplex.setParam(IloCplex::ImplBd,-1); cplex.setParam(IloCplex::DisjCuts,-1); cplex.solve(); env.out() << endl << "Optimal value: " << cplex.getObjValue() << endl; env.out()<< "Number of Cuts added: " << numCuts <= 1 - eps) env.out() << "At time " << t << " produced " << cplex.getValue(product[t]) << " " << cplex.getValue(setup[t]) << endl; } catch(IloException& e) { cerr << " ERROR: " << e << endl; } catch(...) { cerr << " ERROR" << endl; } env.end(); return 0; }