Search in sources :

Example 6 with GRBVar

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;
        }
    }
}
Also used : Line(org.twak.utils.Line) GRBLinExpr(gurobi.GRBLinExpr) Point2d(javax.vecmath.Point2d) Color(java.awt.Color) GRBVar(gurobi.GRBVar)

Example 7 with GRBVar

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);
}
Also used : GRBLinExpr(gurobi.GRBLinExpr) GRBVar(gurobi.GRBVar) MFPoint(org.twak.tweed.gen.FeatureCache.MFPoint)

Aggregations

GRBVar (gurobi.GRBVar)7 GRBLinExpr (gurobi.GRBLinExpr)6 GRBException (gurobi.GRBException)5 MFPoint (org.twak.tweed.gen.FeatureCache.MFPoint)5 Point2d (javax.vecmath.Point2d)4 Line (org.twak.utils.Line)4 HalfEdge (org.twak.utils.geom.HalfMesh2.HalfEdge)4 GRBEnv (gurobi.GRBEnv)3 GRBModel (gurobi.GRBModel)3 GRBQuadExpr (gurobi.GRBQuadExpr)3 Color (java.awt.Color)3 File (java.io.File)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MegaFeatures (org.twak.tweed.gen.FeatureCache.MegaFeatures)3 Cache2 (org.twak.utils.Cache2)3 MultiMap (org.twak.utils.collections.MultiMap)3 HalfMesh2 (org.twak.utils.geom.HalfMesh2)3 HalfFace (org.twak.utils.geom.HalfMesh2.HalfFace)3 GRB (gurobi.GRB)2