Menu

access all solutions / get next solution

Help
NicholasH
2017-03-23
2017-03-23
  • NicholasH

    NicholasH - 2017-03-23

    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:

        //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
  • kris

    kris - 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

     
  • NicholasH

    NicholasH - 2017-03-23

    First of all: Thank you for you help!
    Second: So once you get all solutions, you can only view the last one?

    Nicholas

     
  • kris

    kris - 2017-03-23

    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

     
    • NicholasH

      NicholasH - 2017-03-23

      Yes it does,

      Thanks for your help!

      Kind regards,

      Nicholas

       

Log in to post a comment.