PySCIPOpt icon indicating copy to clipboard operation
PySCIPOpt copied to clipboard

Using methods (quicksum, exp, log) yields "Error in input data" in Constraint Handler but not in main model

Open Joao-Dionisio opened this issue 4 years ago • 1 comments

Hello. I am trying to build a constraint handler, below is a minimal working example, based on the subtour elimination example.

class tempconshdlr(Conshdlr):

    def __init__(self, variables):
        self.variables = variables

    def temp_const(self, solution = None):
        real_temp, rul, q = self.variables
        
        temp_misses = []

        for pt in PTs:
            for t in range(1,Tmax+1):                
                cur_temp = self.model.getSolVal(solution, real_temp[pt,t])   
                if cur_temp > 10:
                    temp_misses.append([pt,t])               
        return temp_misses            
    
    def conscheck(self, constraints, solution, check_integrality,
                  check_lp_rows, print_reason, completely, **results):
        if self.temp_const(solution):
            return {"result": SCIP_RESULT.INFEASIBLE}
        else:
            return {"result": SCIP_RESULT.FEASIBLE}

    # enforces LP solution
    def consenfolp(self, constraints, n_useful_conss, sol_infeasible):
        temp_misses = self.temp_const()
        if temp_misses:
            real_temp= self.variables
            for pt,t in temp_misses:
                self.model.addCons(real_temp[pt,t] <= exp(2)) # the error appears here
                print("cut temp: pt %i at %i" % (pt, t))
            return {"result": SCIP_RESULT.CONSADDED}
        else:
            return {"result": SCIP_RESULT.FEASIBLE}

    def conslock(self, constraint, locktype, nlockspos, nlocksneg):
        pass

I have already managed to create other constraint handlers, and messing with my code suggests that the problem is indeed exclusive to the constraint handler, since I can use exp, log and quicksum (which also raise the same error) in the main model just fine. This is the error message:

Traceback (most recent call last):
  File "c:\Users\jdion\OneDrive\Ambiente de Trabalho\Doutoramento\Trabalho\Models\PySCIPOpt\const_handler.py", line 337, in conscheck
    if self.temp_const(solution):
  File "c:\Users\jdion\OneDrive\Ambiente de Trabalho\Doutoramento\Trabalho\Models\PySCIPOpt\const_handler.py", line 324, in temp_const
    if cur_temp != quicksum([2,3,4,5,6]):
  File "src/pyscipopt/expr.pxi", line 270, in pyscipopt.scip.Expr.__richcmp__
  File "src/pyscipopt/expr.pxi", line 80, in pyscipopt.scip._expr_richcmp
NotImplementedError
Exception ignored in: 'pyscipopt.scip.PyConsCheck'
Traceback (most recent call last):
  File "c:\Users\jdion\OneDrive\Ambiente de Trabalho\Doutoramento\Trabalho\Models\PySCIPOpt\const_handler.py", line 337, in conscheck
    if self.temp_const(solution):
  File "c:\Users\jdion\OneDrive\Ambiente de Trabalho\Doutoramento\Trabalho\Models\PySCIPOpt\const_handler.py", line 324, in temp_const
    if cur_temp != quicksum([2,3,4,5,6]):
  File "src/pyscipopt/expr.pxi", line 270, in pyscipopt.scip.Expr.__richcmp__
  File "src/pyscipopt/expr.pxi", line 80, in pyscipopt.scip._expr_richcmp
NotImplementedError:
[cons.c:3774] ERROR: Error <0> in function call
[sol.c:1743] ERROR: Error <0> in function call
[primal.c:1522] ERROR: Error <0> in function call
[scip_sol.c:3192] ERROR: Error <0> in function call
[heur_trivial.c:175] ERROR: Error <0> in function call
[heur.c:1303] ERROR: Error <0> in function call
[solve.c:355] ERROR: Error <0> in function call
[solve.c:3817] ERROR: Error <0> in function call
[solve.c:4190] ERROR: Error <0> in function call
[solve.c:4984] ERROR: Error <0> in function call
[scip_solve.c:2748] ERROR: Error <0> in function call

I understand it says "NotImplementedError", but I haven't seen this issue discussed yet, and it seems a bit strange the disconnect between the handler and the main model.

I attach my files, if you want to take a closer look (they're very messy). code.zip

Thank in advance, João Dionísio

Joao-Dionisio avatar May 11 '22 15:05 Joao-Dionisio

I opened this issue a while ago, when I knew even less about PySCIPOpt that I know now.

Joao-Dionisio avatar Oct 19 '22 09:10 Joao-Dionisio