Decision Optimization

 View Only
  • 1.  SIGSEGV when calling solve() in CPLEX

    Posted Wed June 03, 2020 04:00 PM

    As the title suggests, Java Runtime Environment throws me a simple segmentation error after I'm calling solve ().

    I don't understand if it is an incompatibility problem with the JRE or something else. The code runs on a Docker container, especially on Linux Alpine distro. The same code on Windows does not create problems.

    Here is a screen shot of the error:

    SIGSEGV
    TThat's the code:
    System.out.println("1");
        cplex = new IloCplex();
        System.out.println("2");
        IloIntVar z = cplex.intVar(0, Integer.MAX_VALUE, "z");
        IloIntVar[] x = new IloIntVar[hotels.size()];
        IloIntVar[][] y = new IloIntVar[maxNumberOfRooms][hotels.size()];
        IloIntVar[][] g = new IloIntVar[maxNumberOfRooms][hotels.size()];
        IloLinearNumExpr linearNumExpr2 = cplex.linearNumExpr();
        IloLinearNumExpr linearNumExpr4 = cplex.linearNumExpr();
        IloLinearIntExpr linearIntExpr = cplex.linearIntExpr();
        IloLinearNumExpr objective = cplex.linearNumExpr();
        List<IloRange> constraints = new ArrayList<>();
        IloIntExpr[] intExprs = new IloIntExpr[hotels.size()];
        List<HashMap<String, Object>> hotelRooms = new LinkedList<>();
        double newScalarProduct = 0.0;
        double yMax = days;
        double yMin = 0.1;
    
        for (int i = 0; i < hotels.size(); ++i) {
            IloLinearNumExpr linearNumExpr1 = cplex.linearNumExpr();
            IloLinearNumExpr linearNumExpr3 = cplex.linearNumExpr();
            x[i] = cplex.intVar(0, Integer.MAX_VALUE, ("x" + i));
            linearIntExpr.addTerm(1, x[i]);
    
            for (int j = 0; j < maxNumberOfRooms; ++j) {
                y[j][i] = cplex.intVar(0, days, ("y" + j + i));
                g[j][i] = cplex.intVar(0, 1, ("g" + j + i));
                linearNumExpr1.addTerm(pricePerNight[j][i], y[j][i]);
                linearNumExpr3.addTerm(places[j][i], g[j][i]);
            }
    
            objective.addTerm(certainties.get(i), x[i]);
            linearNumExpr2.add(linearNumExpr1);
            linearNumExpr4.add(linearNumExpr3);
        }
    
        for (int i = 0; i < hotels.size(); ++i) {
            IloLinearIntExpr linearIntExpr1 = cplex.linearIntExpr();
    
            for (int j = 0; j < maxNumberOfRooms; ++j) {
                linearIntExpr1.addTerm(1, y[j][i]);
                constraints.add((IloRange) cplex.addGe(y[j][i], cplex.prod(yMin, g[j][i])));
                constraints.add((IloRange) cplex.addLe(y[j][i], cplex.prod(yMax, g[j][i])));
            }
    
            intExprs[i] = cplex.abs(cplex.diff(x[i], 1));
            constraints.add((IloRange)cplex.addEq(linearIntExpr1, x[i]));
        }
    
        for (Double scalarProduct : solToDiscard) {
            IloLinearNumExpr linearNumExpr_ = cplex.linearNumExpr();
            linearNumExpr_.addTerms(coefficients, x);
            constraints.add(cplex.addGe(cplex.abs(cplex.diff(linearNumExpr_, scalarProduct)), 0.001));
        }
    
        constraints.add((IloRange)cplex.addEq(cplex.sum(intExprs), z));
        constraints.add(cplex.addLe(linearIntExpr, days));
        constraints.add(cplex.addLe(linearNumExpr2, budget));
        constraints.add(cplex.addGe(linearNumExpr4, numPeople));
        cplex.addMaximize(cplex.diff(objective, z));
    
        System.out.println("3");
        if (cplex.solve()) {
            System.out.println("8");
            int realDays = 0;
            for (int j = 0; j  < hotels.size(); ++j) {
                realDays += cplex.getValue(x[j]);
                System.out.println("5");
                for (int i = 0; i < maxNumberOfRooms; ++i) {
                    if (cplex.getValue(y[i][j]) > 0) {
                        HashMap<String, Object> hm = new HashMap<String, Object>();
                        hm.put("Room", hotelsRooms.get(hotels.get(j).getId()).get(i));
                        hm.put("DaysInRoom", cplex.getValue(y[i][j]));
                        System.out.println("y" + i + j + " :" + cplex.getValue(y[i][j]));
                        hotelRooms.add(hm);
                    }
                }
            }


    Clearly it prints the 3, but it doesn't prints the 8... I also tried to increase the heap dedicated to the process, but nothing ...





    ------------------------------
    Alberto Guastalla
    ------------------------------

    #DecisionOptimization


  • 2.  RE: SIGSEGV when calling solve() in CPLEX

    Posted Wed June 03, 2020 06:22 PM
    This question was cross-posted on stackoverflow here. I left a comment there.

    ------------------------------
    Ryan Kersh
    ------------------------------