void runConflictRefinerAllConflicts(IloCP cp, IloConstraintArray cts) { IloEnv env = cp.getEnv(); IloInt n = cts.getSize(); IloNumArray prefs(env, n); IloInt i; IloIntArray2 forbiddenCts(env); // Initial iteration: no forbidden constraints forbiddenCts.add(IloIntArray(env)); while (0<forbiddenCts.getSize()) { IloIntArray forbidden = forbiddenCts[0]; forbiddenCts.remove(0); for (i=0; i<n; ++i) { prefs[i]=1.0; // Initialize to normal preference } for (i=0; i<forbidden.getSize(); ++i) { prefs[forbidden[i]]=-1.0; // Remove constraint } if (cp.refineConflict(cts, prefs)) { cp.writeConflict(cp.out()); // Next iterations for (i=0; i<n; ++i) { if (cp.getConflict(cts[i])==IloCP::ConflictMember) { IloIntArray newforbidden(env, 1, i); newforbidden.add(forbidden); forbiddenCts.add(newforbidden); } } } forbidden.end(); } }
void runConflictRefinerWithPreferences(IloCP cp, IloConstraintArray preferredCts, IloConstraintArray otherCts) { IloEnv env = cp.getEnv(); IloConstraintArray cts(env); IloNumArray prefs(env); IloInt i; for (i=0; i<otherCts.getSize(); ++i) { cts.add(otherCts[i]); prefs.add(1.0); // Normal preference } for (i=0; i<preferredCts.getSize(); ++i) { cts.add(preferredCts[i]); prefs.add(2.0); // Higher preference } if (cp.refineConflict(cts, prefs)) { cp.writeConflict(cp.out()); } cts.end(); prefs.end(); }
py::list CplexTSPSolver::nextRelaxation() { IloInt n = N*N; py::list ret; IloNumArray sol(env, n); if(!first) { cplex.getValues(sol, x); IloConstraintArray constraints = subtourEliminationConstraint(env, N, sol, x, 10e-5, v); for(int i=0; i<constraints.getSize(); i++) model.add(constraints[i]); std::cout << constraints.getSize() << " Constraints\n"; if(!constraints.getSize()) { std::cout << "finished!\n"; return ret; // return empty list } constraints.end(); cplex.solve(); } first = false; cplex.getValues(sol, x); //return adjacency matrix as pyList for(int i=0; i<n; ++i) ret.append(sol[i]); sol.end(); return ret; }
void runConflictRefinerPartition(IloCP cp, IloConstraintArray cts) { IloEnv env = cp.getEnv(); IloInt n = cts.getSize(); IloNumArray prefs(env, n); IloInt i; for (i=0; i<n; ++i) { prefs[i]=1.0; // Normal preference } while (cp.refineConflict(cts, prefs)) { cp.writeConflict(cp.out()); for (i=0; i<n; ++i) { if (cp.getConflict(cts[i])==IloCP::ConflictMember) { prefs[i]=-1.0; // Next run will ignore constraints of the current conflict } } } prefs.end(); }