Skip to content

Can I use ExprCons for model.addConsNode()? #391

@purin0604

Description

@purin0604

Hi,

I would like to add some constraints locally using model.addConsNode().
(Set some variables to be zero. )
From coloring examples and documents, I learned it should be something like:

Class myConshdlr(Conshdlr):

    def consprop(self, constraints, nusefulconss, nmarkedconss, proptiming):
         for var in self.model.vars:      
               if condition is True:
                  self.model.chgVarUb(var, 0.0)
        return {"result": SCIP_RESULT.DIDNOTFIND}

    # fundamental callbacks 
    def consenfolp(self, constraints, nusefulconss, solinfeasible):
        return {"result": SCIP_RESULT.FEASIBLE}
    def conscheck(self, constraints, solution, checkintegrality, checklprows, printreason):
        return {"result": SCIP_RESULT.FEASIBLE}
    def conslock(self, constraint, nlockspos, nlocksneg):
        return {"result": SCIP_RESULT.FEASIBLE}

con1 = model.createCons(myConshdlr, "my constraint", stickingatnode=True)
model.addConsNode(node, con1) 

  1. Is using constraint handler the only way to create constraints locally and use addConsNode()?
    Is there any simpler way to add constraint at node, like using constraint expression in addCons()?
    Such as
         for var in self.model.vars:      
               if condition is True:
                  model.addConsNode(var == 0)
  1. What does "stickingatnode" parameter in the model.createCons() do?

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions