#include #include using namespace std; #define EPSL 0.0001 ILOSTLBEGIN const char* Cores[] = {"blue", "white", "yellow", "green"}; const char* Paises[] = {"Belgium", "Denmark", "France", "Germany", "Luxembourg", "Netherlands"}; vector > edges = { {0, 2}, {0, 3}, {0, 5}, {0, 4}, {1, 3}, {2, 3}, {2, 4}, {3, 4}, {3, 5}}; typedef IloArray IloIntVarArray2; int main(){ IloEnv env; try{ IloInt nPaises = 6; IloInt nCores = 4; IloIntVarArray2 X(env); for(IloInt p = 0; p < nPaises; p++){ X.add(IloIntVarArray(env, nCores, 0, 1)); } IloModel model(env); for(unsigned e = 0; e < edges.size(); e++){ int u = edges[e].first; int v = edges[e].second; for(unsigned c = 0; c < nCores; c++){ model.add(X[u][c] + X[v][c] <= 1); } } for(IloInt p = 0; p < nPaises; p++){ model.add(IloSum(X[p]) == 1); } IloCplex solver(model); solver.solve(); cout << solver.getStatus() << endl; for(IloInt p = 0; p < nPaises; p++){ cout << Paises[p] << ": "; for(unsigned c = 0; c < nCores; c++){ if(solver.getValue(X[p][c]) >= 1 - EPSL) cout << Cores[c]; } cout << endl; } } catch (IloException& ex) { cerr << "Error: " << ex << endl; } catch (...) { cerr << "Error" << endl; } env.end(); return 0; }