public IConstr addExactly(IVecInt literals, IVec<BigInteger> coeffs, BigInteger weight) throws ContradictionException { StringBuffer out = getOut(); assert literals.size() == coeffs.size(); this.nbOfConstraints++; int n = literals.size(); if (n > 0) { out.append(coeffs.get(0)); out.append("x"); out.append(literals.get(0)); out.append(" "); } BigInteger coeff; for (int i = 1; i < n; i++) { coeff = coeffs.get(i); if (coeff.signum() > 0) { out.append("+ " + coeff); } else { out.append("- " + coeff.negate()); } out.append("x"); out.append(literals.get(i)); out.append(" "); } out.append("= "); out.append(weight); out.append(" \n"); return FAKE_CONSTR; }
public void objectiveFunctionToLP(ObjectiveFunction obj, StringBuffer buffer) { buffer.append("Minimize \n"); buffer.append("obj: "); IVecInt variables = obj.getVars(); IVec<BigInteger> coeffs = obj.getCoeffs(); int n = variables.size(); if (n > 0) { buffer.append(coeffs.get(0)); buffer.append("x"); buffer.append(variables.get(0)); buffer.append(" "); } BigInteger coeff; for (int i = 1; i < n; i++) { coeff = coeffs.get(i); if (coeff.signum() > 0) { buffer.append("+ " + coeff); } else { buffer.append("- " + coeff.negate()); } buffer.append("x"); buffer.append(variables.get(i)); buffer.append(" "); } }