I'm currently using JaCoP as a graph colorer (which works pretty great), but I was wondering if it is possible in JaCoP to access a certain solution instead of the last one... Also i've some kind of getNextSolution() method would exist this would be very handy.
My current code is the following:
//Code
Store store = new Store();
int size = graph.getNodes().size();
IntVar[] v = new IntVar[size];
for (int i=0; i<size; i++)
v[i] = new IntVar(store, "v"+i, 1, nTeams/2); // define constraints
// If their is an edge between 2 nodes they can't have the same color
for (Edge edge: graph.getEdges()) {
int x = edge.getNode1().getGame().getGameNumber()-1;
int y = edge.getNode2().getGame().getGameNumber()-1;
store.impose(new XneqY(v[x], v[y]));
}
Search<IntVar> search = new DepthFirstSearch<IntVar>();
SelectChoicePoint<IntVar> select = new InputOrderSelect<IntVar>(store, v, new IndomainMin<IntVar>());
boolean result = search.labeling(store, select);
Kind Regards,
Nicholas
Last edit: NicholasH 2017-03-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your question basically addresses the problem of a solution iterator. No, it does not exist in JaCoP. You can search for a single solution, all solutions or get a solution with minimla cost.
Best regards,
/Kris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I'm currently using JaCoP as a graph colorer (which works pretty great), but I was wondering if it is possible in JaCoP to access a certain solution instead of the last one... Also i've some kind of getNextSolution() method would exist this would be very handy.
My current code is the following:
Kind Regards,
Nicholas
Last edit: NicholasH 2017-03-23
Hi!
Your question basically addresses the problem of a solution iterator. No, it does not exist in JaCoP. You can search for a single solution, all solutions or get a solution with minimla cost.
Best regards,
/Kris
First of all: Thank you for you help!
Second: So once you get all solutions, you can only view the last one?
Nicholas
Your search in the included code searches for the first leagal solution and this you will get. You cna search for all solutions if you add
search.getSolutionListener().searchAll(true);
search.getSolutionListener().recordSolutions(true);
before search. Then you can access all solutions, by for example, statement
search.getSolutionListener().printAllSolutions()
or access solutions separately, as described in http://jacopguide.osolpro.com/guideJaCoP.html#x1-530001
Hope it clarifies my previous answer.
Best,
/Kris
Yes it does,
Thanks for your help!
Kind regards,
Nicholas