chocoteam / choco-solver

An open-source Java library for Constraint Programming
http://choco-solver.org/
BSD 4-Clause "Original" or "Old" License
688 stars 138 forks source link

[BUG] IllegalAccesError triggered by Solver.findParetoFront() #730

Closed mrattfeldt closed 4 years ago

mrattfeldt commented 4 years ago

Expected behavior

No IllegalAccessError should be generated.

Actual behavior

Exception in thread "main" java.lang.IllegalAccessError: tried to access field org.chocosolver.sat.SatSolver.ok_ from class org.chocosolver.solver.constraints.nary.sat.PropSat
    at org.chocosolver.solver.constraints.nary.sat.PropSat.propagate(PropSat.java:100)
    at org.chocosolver.solver.propagation.PropagationEngine.execute(PropagationEngine.java:225)
    at org.chocosolver.solver.propagation.PropagationEngine.activatePropagators(PropagationEngine.java:209)
    at org.chocosolver.solver.propagation.PropagationEngine.propagate(PropagationEngine.java:173)
    at org.chocosolver.solver.search.loop.propagate.PropagateBasic.execute(PropagateBasic.java:46)
    at org.chocosolver.solver.Solver.initialize(Solver.java:367)
    at org.chocosolver.solver.Solver.solve(Solver.java:255)
    at org.chocosolver.solver.search.IResolutionHelper.findParetoFront(IResolutionHelper.java:478)
    at Pareto.main(Pareto.java:58)

Possible Solution

Possible a JPMS issue. See also https://github.com/chocoteam/choco-solver/issues/699

Steps to Reproduce (for bugs)

The problem is triggered when running the following model (taken from https://www.cosling.com/choco-solver/pareto).

/*
 * Copyright (C) 2017 COSLING S.A.S.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.variables.IntVar;

import java.util.List;

/**
 * Simple Choco Solver example involving multi-objective optimization
 * @author Jean-Guillaume FAGES (cosling)
 * @version choco-solver-4.0.4
 */
public class Pareto {

    public static void main(String[] args) {
        // We handle 4 types of food, described below
        int[] nbItems = new int[]{5, 2, 6, 7}; // number of items for each type
        int[] weights = new int[]{5, 8, 7, 8}; // weight of an item for each type
        int[] lipids  = new int[]{5, 9, 8, 1}; // quantity of lipids of the item
        int[] glucose = new int[]{9, 5, 7, 32}; // quantity of glucose of the item

        Model model = new Model("ParetoKnapsack");

        // For each type, we create a variable for the number of occurrences
        IntVar[] occurrences = new IntVar[nbItems.length];
        for (int i = 0; i < nbItems.length; i++) {
            occurrences[i] = model.intVar(0, nbItems[i]);
        }

        // Total weight of the solution.
        IntVar weight = model.intVar(0, 80);
        // Total of lipids
        IntVar totalLipids = model.intVar(0, 200);
        // Total of glucose
        IntVar totalGlucose = model.intVar(0, 200);

        // We add two knapsack constraints to the solver
        // Beware : call the post() method to save it
        model.knapsack(occurrences, weight, totalLipids, weights, lipids).post();
        model.knapsack(occurrences, weight, totalGlucose, weights, glucose).post();

        // Optimise independently two variables using the Pareto optimizer
        List<Solution> solutions = model.getSolver().findParetoFront(new IntVar[]{totalLipids, totalGlucose},Model.MAXIMIZE);
        for (Solution solution : solutions) {
            System.out.println("-----------------------------------");
            System.out.println("W: " + solution.getIntVal(weight) + "\t G:" + solution.getIntVal(totalGlucose) + "\t L: " + solution.getIntVal(totalLipids));
            System.out.println("Strawberry jam: " + solution.getIntVal(occurrences[0]));
            System.out.println("Bananas: " + solution.getIntVal(occurrences[1]));
            System.out.println("Apples: " + solution.getIntVal(occurrences[2]));
            System.out.println("Honey: " + solution.getIntVal(occurrences[3]));
        }
        System.out.println("There are "+solutions.size()+" Pareto-optimal solutions");
    }
}

Context

Environment

cprudhom commented 4 years ago

I started a fresh maven project with the following dependencies:

    <dependencies>
        <dependency>
            <groupId>org.choco-solver</groupId>
            <artifactId>choco-solver</artifactId>
            <version>4.10.4</version>
        </dependency>
    </dependencies>

added the bunch of code you pasted, and run the following commands:

$ mvn clean install -DskipTests -U
$ java -cp .:/Users/cprudhom/.m2/repository/org/choco-solver/choco-solver/4.10.4/choco-solver-4.10.4-jar-with-dependencies.jar:./target/untitled-1.0-SNAPSHOT.jar Pareto

-U means that dependencies should be updated (to avoid, in my case, to rely on my repository), and got this output:

-----------------------------------
W: 75    G:195   L: 45
Strawberry jam: 0
Bananas: 0
Apples: 5
Honey: 5
...

Could double-check your configuration?

--- EDIT --- Ok, I am able to reproduce the bug after purging dependencies.

cprudhom commented 4 years ago

I must release once again.. Thank for the bug detection btw.

glelouet commented 4 years ago

That's the reason why I posted this :

https://github.com/chocoteam/choco-solver/issues/699#issuecomment-688855606

This ensures you have all fresh dependencies. I also wrote in my PR that I was having issues with compilation issues and I could not test my changes because of them.

Also the compilation issue I had should have been fixed if you removed the geost dependency (the one you told me should be removed)

edit : fixed misuses of words.

cprudhom commented 4 years ago

That will be part of the next release