int testGurobi(){ int nCustomers = 5; GRBEnv* env = 0; GRBVar **y =0; GRBVar ***x=0; GRBVar ***z=0; double relaxedVal = 0.0; try { int nDays = 3; int nSchedules = 7; int Capacity = 289; int dailyDemand[6] = {0,65,35,58,24,11}; double holdRate[6] = {0,0.23,0.32,0.33,0.23,0.18 }; double holdRate_depot[6] = {0,0.23,0.32,0.33,0.23,0.18}; double arcCost[7][7] = { {0, 84, 348, 17, 202, 289, 0}, {84, 0, 264, 101, 213, 226, 84}, {348, 264, 0, 365, 367, 238, 348}, {17, 101, 365, 0, 207, 301, 17 }, {202, 213, 367, 207, 0, 430, 202}, {289, 226, 238, 301, 430, 0, 289 }, {0, 84, 348, 17, 202, 289, 0 }, }; int *maxSchedule; maxSchedule = new int[nSchedules]; int schedule[3][7] = { { 1, 1, 0, 1, 1, 0, 0 }, { 1, 1, 1, 0, 0, 1, 0 }, { 1, 0, 1, 1, 0, 0, 1 } }; int scheduleAmount[3][7] ={ { 1, 2, 0, 1, 3, 0, 0 }, { 1, 1, 2, 0, 0, 3, 0 }, { 1, 0, 1, 2, 0, 0, 3 } }; //find the max unit in the schedule column for(int j = 0 ; j= temp2[j]) temp2[j] = scheduleAmount[day][j]; } holdingCost[i][j] = holdRate[i]*dailyDemand[i]*temp1[j]+holdRate_depot[i]*dailyDemand[i]*(nDays*(temp2[j]-1)-temp1[j]); //cout<< "\n"<< i << " - " << j+1 << holdingCost[i][j] ; } } // Model env = new GRBEnv(); //gMainGRBModel = new GRBModel(*env); //GRBModel model = *gMainGRBModel; GRBModel model = GRBModel(*env); model.set(GRB_StringAttr_ModelName, "loadrelax"); //z variable z = new GRBVar ** [nCustomers+2]; for (int i = 0; i < nCustomers+2; i++) { z[i] = new GRBVar *[nCustomers +2]; for (int j = 0; j < nCustomers+2; j++) { z[i][j] = model.addVars(nDays); for (int t = 0; t < nDays; t++) { string s = "z_" + itos(i) + "_"+ itos(j) + "_"+itos(t); z[i][j][t] = model.addVar(0.0, Capacity, 0.0, GRB_CONTINUOUS, s); } } } //y variable y = new GRBVar *[nCustomers+1]; for(int i =0; i < nCustomers+1;i++) { y[i] = model.addVars(nSchedules); //yCt++; //model.update(); for(int s =0;s< nSchedules;s++) y[i][s]=model.addVar(0.0,1.0,0.0,GRB_BINARY,"y_"+itos(i)+ "_" + itos(s)); //y[i][s]=model.addVar(0.0,1.0,0.0,GRB_CONTINUOUS,"y_var_"+itos(i)+ "_"+itos(s)); } //x variable x = new GRBVar ** [nCustomers+2]; for (int i = 0; i < nCustomers+2; i++) { x[i] = new GRBVar *[nCustomers +2]; for (int j = 0; j < nCustomers+2; j++) { if( j > i && !(j==nCustomers+1 && i ==0)) { x[i][j] = model.addVars(nDays); for (int t = 0; t < nDays; t++) { string s = "x_" + itos(i) + "_"+itos(j) + "_"+itos(t); //x[i][j][t] = model.addVar(0.0, 1.0, 0.0, GRB_CONTINUOUS, s); x[i][j][t] = model.addVar(0.0, 1.0, 0.0, GRB_BINARY, s); } } } } // Update model to integrate new variables model.update(); //difference b/n the sum of the commodity flow variables associated with arcs entering and leaving each vertex i is twice the demand of i. for(int i=1;i< nCustomers+1;++i) { for(int t=0;t < nDays;t++) { GRBLinExpr ntot1 = 0; for(int j=0;j< nCustomers+2;++j) { if(i!=j) { ntot1 += (z[j][i][t] - z[i][j][t]); } } GRBLinExpr ntot2 = 0; for(int s=0; sj) ) if( j > i && !(j==nCustomers+1 && i ==0)) { string s = "Constraint2_" + itos(i) + "_" + itos(j) + "_" + itos(t); model.addConstr(z[i][j][t] + z[j][i][t] == Capacity*(x[i][j][t]), s); } } } } ////constraint 3 for (int t=0; t < nDays; ++t) { GRBLinExpr ntot3 = 0; for(int i = 1; i < nCustomers + 1 ; ++i) { for(int s = 0 ;s i && !(j==nCustomers+1 && i ==0)) ntot1 += x[i][j][t]; else if ( ji && !(j==nCustomers+1 && i ==0)) obj += arcCost[i][j]*x[i][j][t]; } } } for(int i = 1; i < nCustomers+1 ; ++i) { for(int s=0 ; s < nSchedules ; ++s) { obj += holdingCost[i][s] * y[i][s]; } } model.setObjective(obj,GRB_MINIMIZE); model.optimize(); int status = model.get(GRB_IntAttr_Status); cout<