/** Print the objects. */ public void debugPrint() { if (!readyToUse) finish(); for (VarType cv : outList) { System.out.printf("\t%s\n", cv.toString()); } }
// <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [-LINEAR] [ ":" <DEFAULTVAL> ] private void readParam(String statement) throws IOException { String name; String defaultVal = null; ColorSpace colorSpace = null; String[] split = statement.split(":"); // Parse default val if (split.length == 1) { // Doesn't contain default value } else { if (split.length != 2) { throw new IOException("Parameter statement syntax incorrect"); } statement = split[0].trim(); defaultVal = split[1].trim(); } if (statement.endsWith("-LINEAR")) { colorSpace = ColorSpace.Linear; statement = statement.substring(0, statement.length() - "-LINEAR".length()); } // Parse ffbinding int startParen = statement.indexOf("("); if (startParen != -1) { // get content inside parentheses int endParen = statement.indexOf(")", startParen); String bindingStr = statement.substring(startParen + 1, endParen).trim(); // don't care about bindingStr statement = statement.substring(0, startParen); } // Parse type + name split = statement.split(whitespacePattern); if (split.length != 2) { throw new IOException("Parameter statement syntax incorrect"); } VarType type; if (split[0].equals("Color")) { type = VarType.Vector4; } else { type = VarType.valueOf(split[0]); } name = split[1]; Object defaultValObj = null; if (defaultVal != null) { defaultValObj = readValue(type, defaultVal); } if (type.isTextureType()) { materialDef.addMaterialParamTexture(type, name, colorSpace); } else { materialDef.addMaterialParam(type, name, defaultValObj); } }
/** Tests if two containers have contain same things. Can be used to answer the alias query. */ public boolean hasNonEmptyIntersection(PtSensVisitor<VarType> other) { // Using table view for comparison, that's faster for (Map.Entry<Node, List<VarType>> entry : tableView.entrySet()) { Node var = entry.getKey(); List<VarType> list1 = entry.getValue(); List<VarType> list2 = other.getCSList(var); if (list1.size() == 0 || list2.size() == 0) continue; for (VarType cv1 : list1) { for (VarType cv2 : list2) if (cv1.intersect(cv2)) return true; } } return false; }
@Override public VarType evaluate() { VarType a = lhs.evaluate(); VarType b = rhs.evaluate(); if (a.isBoolean() && b.isBoolean()) { return new VarType(a.asBoolean() && b.asBoolean()); } if (a.isDrawable() && b.isDrawable()) { Drawable aP = a.asDrawable(); Drawable bP = b.asDrawable(); this.fireDrawableEvent(CustomEvent.REMOVE_DRAWABLE, aP); this.fireDrawableEvent(CustomEvent.REMOVE_DRAWABLE, bP); Drawable d = PolyBoolean.intersection(aP, bP); // TODO: add actual line number instead of 0 here this.fireDrawableEvent(CustomEvent.DRAWABLE_CREATED, d); // d.setLine(line); return new VarType(d); } else { throw new RuntimeException("illegal expression: " + this); } }
private Object readValue(final VarType type, final String value) throws IOException { if (type.isTextureType()) { return parseTextureType(type, value); } else { String[] split = value.trim().split(whitespacePattern); switch (type) { case Float: if (split.length != 1) { throw new IOException("Float value parameter must have 1 entry: " + value); } return Float.parseFloat(split[0]); case Vector2: if (split.length != 2) { throw new IOException("Vector2 value parameter must have 2 entries: " + value); } return new Vector2f(Float.parseFloat(split[0]), Float.parseFloat(split[1])); case Vector3: if (split.length != 3) { throw new IOException("Vector3 value parameter must have 3 entries: " + value); } return new Vector3f( Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2])); case Vector4: if (split.length != 4) { throw new IOException("Vector4 value parameter must have 4 entries: " + value); } return new ColorRGBA( Float.parseFloat(split[0]), Float.parseFloat(split[1]), Float.parseFloat(split[2]), Float.parseFloat(split[3])); case Int: if (split.length != 1) { throw new IOException("Int value parameter must have 1 entry: " + value); } return Integer.parseInt(split[0]); case Boolean: if (split.length != 1) { throw new IOException("Boolean value parameter must have 1 entry: " + value); } return Boolean.parseBoolean(split[0]); default: throw new UnsupportedOperationException("Unknown type: " + type); } } }
/* * (non-Javadoc) * * @see net.sf.javailp.Solver#solve(net.sf.javailp.Problem) */ public Result solve(Problem problem) { Map<IloNumVar, Object> numToVar = new HashMap<IloNumVar, Object>(); Map<Object, IloNumVar> varToNum = new HashMap<Object, IloNumVar>(); try { IloCplex cplex = new IloCplex(); initWithParameters(cplex); for (Object variable : problem.getVariables()) { VarType varType = problem.getVarType(variable); Number lowerBound = problem.getVarLowerBound(variable); Number upperBound = problem.getVarUpperBound(variable); double lb = (lowerBound != null ? lowerBound.doubleValue() : Double.NEGATIVE_INFINITY); double ub = (upperBound != null ? upperBound.doubleValue() : Double.POSITIVE_INFINITY); final IloNumVarType type; switch (varType) { case BOOL: type = IloNumVarType.Bool; break; case INT: type = IloNumVarType.Int; break; default: // REAL type = IloNumVarType.Float; break; } IloNumVar num = cplex.numVar(lb, ub, type); numToVar.put(num, variable); varToNum.put(variable, num); } for (Constraint constraint : problem.getConstraints()) { IloLinearNumExpr lin = cplex.linearNumExpr(); Linear linear = constraint.getLhs(); convert(linear, lin, varToNum); double rhs = constraint.getRhs().doubleValue(); switch (constraint.getOperator()) { case LE: cplex.addLe(lin, rhs); break; case GE: cplex.addGe(lin, rhs); break; default: // EQ cplex.addEq(lin, rhs); } } if (problem.getObjective() != null) { IloLinearNumExpr lin = cplex.linearNumExpr(); Linear objective = problem.getObjective(); convert(objective, lin, varToNum); if (problem.getOptType() == OptType.MIN) { cplex.addMinimize(lin); } else { cplex.addMaximize(lin); } } for (Hook hook : hooks) { hook.call(cplex, varToNum); } if (!cplex.solve()) { cplex.end(); return null; } final Result result; if (problem.getObjective() != null) { Linear objective = problem.getObjective(); result = new ResultImpl(objective); } else { result = new ResultImpl(); } for (Entry<Object, IloNumVar> entry : varToNum.entrySet()) { Object variable = entry.getKey(); IloNumVar num = entry.getValue(); VarType varType = problem.getVarType(variable); double value = cplex.getValue(num); if (varType.isInt()) { int v = (int) Math.round(value); result.putPrimalValue(variable, v); } else { result.putPrimalValue(variable, value); } } cplex.end(); return result; } catch (IloException e) { e.printStackTrace(); } return null; }
VarType getThrowParameters(VarType t) { return t.ifItIsParameter(parameters); }