/************************************************************************************ * The model shows a Benders Decomposition for a location-transportation problem. * * The original MIP is decomposed into two problems. * * The subproblem is using the dual formulation. * * Version: 1.0, April 10th, 2005, Tested with CPLEX v9.0 * * For consistency, this is built using an equivalent AMPL model cfl.benders.mod * ************************************************************************************/ #include ILOSTLBEGIN typedef IloArray TwoDMatrix; int main(int argc, char **argv) { IloEnv env; try { IloInt i=0, j=0, k=0; IloInt ORIG=0, DEST=0; IloInt MaxCut=0; //Maximum number of cuts IloNumArray supply(env), demand(env); IloNumArray fix_cost(env); TwoDMatrix var_cost(env); ///////////////// DATA FILE READING //////////////////////////////// const char* filename = "cfl_benders.dat"; if (argc > 1) filename = argv[1]; ifstream file(filename); if (!file) { cerr << "ERROR: could not open file '" << filename << "' for reading" << endl; cerr << "usage: " << argv[0] << " " << endl; throw(-1); } file >> MaxCut >> supply >> demand >> fix_cost >> var_cost ; ORIG = supply.getSize(); DEST = demand.getSize(); IloBool consistentData = (fix_cost.getSize() == ORIG && var_cost.getSize() == ORIG); if (!consistentData) { cerr << "ERROR: data file '" << filename << "' contains inconsistent data" << endl; throw(-1); } /////////////////// DECISION VARIABLES WITH NAMES ///////////////////////////// ////////DECISION VARIABLES AND PARAMETERS FOR SUBPROBLEM/////////////// IloNumArray build(env, ORIG); // = 1 iff facility built at i IloNumVarArray Supply_Price(env, ORIG, -IloInfinity, 0, ILOFLOAT); IloNumVarArray Demand_Price(env, DEST, -IloInfinity, IloInfinity, ILOFLOAT); ////////DECISION VARIABLES AND PARAMETERS FOR MASTER PROBLEM/////////// IloInt nCut = 0; IloNumArray cut_type(env, MaxCut); //= 0 iff subproblem has optimal solution; //= 1 iff subproblem is unbounded TwoDMatrix supply_price(env, MaxCut); TwoDMatrix demand_price(env, MaxCut); for(i=0; i1-eps){ env.out()<