Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Exception access violation | second model in lazy constraint callback

    Posted Thu October 25, 2018 11:15 AM

    Originally posted by: LaylaM


    Hello everyone!

    I see an error whilst executing CPLEX+Java: 

    #
    # A fatal error has been detected by the Java Runtime Environment:
    #
    #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007fff6096c79d, pid=7256, tid=5548
    #
    # JRE version: Java(TM) SE Runtime Environment (10.0+46) (build 10+46)
    # Java VM: Java HotSpot(TM) 64-Bit Server VM (10+46, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
    # Problematic frame:
    # C  [cplex1280remotejni.dll+0x39c79d]
    #
    # No core dump will be written. Minidumps are not enabled by default on client versions of Windows
    #
    # An error report file with more information is saved as:
    # C:\Users\Layla\IdeaProjects\metamodel\hs_err_pid7256.log
    #
    # If you would like to submit a bug report, please visit:
    #   http://bugreport.java.com/bugreport/crash.jsp
    # The crash happened outside the Java Virtual Machine in native code.
    # See problematic frame for where to report the bug.
    #
    

    The problem occurs inside a Lazy Constraint Callback which contains a function with which I generate a schedule (s) from routing variables (x). The problem occurs during executing "model2.solve()". 

    private double[] setSFromX() {
        double[] retArray = new double[noLocations];
        try {
            IloCplex model2 = new IloCplex();
            IloNumVar[] sNew = new IloNumVar[noLocations];
            for (int i = 0; i<noLocations; i++) {
                sNew[i] = model2.numVar(0.0,tmax);
            }
    
            IloLinearNumExpr obj = model2.linearNumExpr();
            for (int i = 0; i<noLocations; i++) {
                obj.addTerm(sNew[i],1.0);
            }
            model2.addMinimize(obj);
    
            for(int i = 0; i<noLocations; i++) {
                for (int j = 0; j<noLocations; j++) {
                    double xij = this.getValue(x[i][j]);
                    if (xij > 0.9) {
                        IloLinearNumExpr expr = model2.linearNumExpr();
                        expr.addTerm(s[j],1.0);
                        expr.addTerm(s[i],-1.0);
                        model2.addGe(expr,1.0);
                    }
                }
            }
    
            if (model2.solve()) {
                retArray = model2.getValues(sNew);
            }
        } catch (IloException e) {
            e.printStackTrace();
        }
        return retArray;
    }
    

    So my first question: Is it possible to nest a second model (model2) inside a lazy constraint of a first model (which is referenced as "this" in the callback)? 

    Second: How can I make this run? Or should I externalize the second model to another class?

    Thank you :)

    Layla


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Exception access violation | second model in lazy constraint callback

    Posted Thu October 25, 2018 03:30 PM

    First question: Yes, creating and running a model inside a callback should work

    Second question: In lines 21 and 22, you are working with s[] rather than sNew[]. Since the code compiled, I'm guessing s[] exists in a global context. So you're trying to add to model2 constraints involving something that does not belong to model2. I would expect that to throw an exception before getting to the solve command, but maybe not. It definitely appears wrong, though.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Exception access violation | second model in lazy constraint callback

    Posted Thu October 25, 2018 04:57 PM

    Using variables from model1 in model2 is illegal (like Paul suspected) but will unfortunately not throw an exception. Instead it results in undefined behavior which can itself manifest in a crash but can also go completely unnoticed.

    Also note that there is a function IloCplex.numVarArray() that creates an array of variables. That is faster than the loop you use.


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Exception access violation | second model in lazy constraint callback

    Posted Fri October 26, 2018 02:44 AM

    Originally posted by: LaylaM


    Thanks Paul and Daniel, using s instead of sNew was a mistake, I corrected it and the code is running properly now ... 


    #CPLEXOptimizers
    #DecisionOptimization