use of gurobi.GRBVar in project chordatlas by twak.
the class GurobiSkelSolver method notBoth.
private void notBoth(HalfEdge e1, HalfEdge e2, boolean isContraint, double badThingsAreBad) throws GRBException {
GRBLinExpr no = new GRBLinExpr();
no.addTerm(1, edgeInfo.get(e1).isEdge);
no.addTerm(1, edgeInfo.get(e2).isEdge);
if (isContraint) {
model.addConstr(no, GRB.LESS_EQUAL, 1, "bad geom < 1");
} else {
GRBVar bothSelected = model.addVar(0.0, 1.0, 0, GRB.BINARY, BAD_GEOM);
no.addTerm(-2, bothSelected);
model.addConstr(no, GRB.LESS_EQUAL, 1, "bad geom <");
model.addConstr(no, GRB.GREATER_EQUAL, -0.5, "bad geom >");
target.addTerm(badThingsAreBad, bothSelected);
{
Line l1 = e1.line(), l2 = e2.line();
l1.start = new Point2d(l1.start);
l1.end = new Point2d(l1.end);
l2.start = new Point2d(l2.start);
l2.end = new Point2d(l2.end);
l1.moveLeft(-0.1);
l2.moveLeft(-0.1);
PaintThing.debug(new Color(255, 170, 0), 2, l1);
PaintThing.debug(new Color(170, 0, 255), 2, l2);
edgeInfo.get(e1).debug = bothSelected;
}
}
}
use of gurobi.GRBVar in project chordatlas by twak.
the class GurobiSkelSolver method buildIsDifferentColor.
private void buildIsDifferentColor(GRBVar isDifferent, GRBVar[] ac, GRBVar[] bc, String desc) throws GRBException {
GRBLinExpr isEdgeEx = new GRBLinExpr();
GRBLinExpr expr;
for (int c = 0; c < ac.length; c++) {
GRBVar a = ac[c], b = bc[c], xor = model.addVar(0.0, 1.0, 0, GRB.BINARY, XOR + " " + desc);
// if (setVars.containsKey( a ) && setVars.containsKey( b ))
// xor.set( DoubleAttr.Start, (setVars.get(a) == 1) ^ ( setVars.get(b) == 1 ) ? 1 : 0 );
expr = new GRBLinExpr();
expr.addTerm(1, a);
expr.addTerm(1, b);
model.addConstr(xor, GRB.LESS_EQUAL, expr, "same color " + c);
expr = new GRBLinExpr();
expr.addTerm(1, a);
expr.addTerm(-1, b);
model.addConstr(xor, GRB.GREATER_EQUAL, expr, "same color " + c);
expr = new GRBLinExpr();
expr.addTerm(-1, a);
expr.addTerm(1, b);
model.addConstr(xor, GRB.GREATER_EQUAL, expr, "same color " + c);
expr = new GRBLinExpr();
expr.addTerm(1, a);
expr.addTerm(1, b);
expr.addTerm(1, xor);
model.addConstr(expr, GRB.LESS_EQUAL, 2, "same color " + c);
isEdgeEx.addTerm(1, xor);
}
isEdgeEx.addTerm(-2, isDifferent);
model.addConstr(isEdgeEx, GRB.LESS_EQUAL, 0.5, "is different " + desc);
model.addConstr(isEdgeEx, GRB.GREATER_EQUAL, -1.5, "is different " + desc);
}
Aggregations