List of usage examples for org.apache.commons.math3.optim.linear Relationship LEQ
Relationship LEQ
To view the source code for org.apache.commons.math3.optim.linear Relationship LEQ.
Click Source Link
From source file:org.lightjason.agentspeak.action.builtin.TestCActionMathLinearprogram.java
/** * test solve maximum/*from w w w .j av a 2 s .com*/ */ @Test public final void solvemaximize() { final List<ITerm> l_return = new ArrayList<>(); final ImmutablePair<LinearObjectiveFunction, Collection<LinearConstraint>> l_linearprogrammax = new ImmutablePair<>( new LinearObjectiveFunction(new double[] { 3, 5 }, 0.0), new HashSet<LinearConstraint>()); l_linearprogrammax.getRight().add(new LinearConstraint(new double[] { 2, 8 }, Relationship.LEQ, 13)); l_linearprogrammax.getRight().add(new LinearConstraint(new double[] { 5, -1 }, Relationship.LEQ, 11)); l_linearprogrammax.getRight().add(new LinearConstraint(new double[] { 1, 0 }, Relationship.GEQ, 0)); l_linearprogrammax.getRight().add(new LinearConstraint(new double[] { 0, 1 }, Relationship.GEQ, 0)); new CSolve().execute(false, IContext.EMPTYPLAN, Stream.of(l_linearprogrammax, "maximize", "non-negative") .map(CRawTerm::from).collect(Collectors.toList()), l_return); Assert.assertArrayEquals(l_return.stream().map(ITerm::raw).toArray(), Stream.of(12.333333333333332, 2, 2.4047619047619047, 1.0238095238095237).toArray()); }
From source file:uk.ac.tgac.metaopt.external.Apache.java
protected Relationship convertRelationship(Constraint.Relation relation) { if (relation == Constraint.Relation.EQUAL) { return Relationship.EQ; } else if (relation == Constraint.Relation.GREATER_THAN_OR_EQUAL_TO) { return Relationship.GEQ; } else if (relation == Constraint.Relation.LESS_THAN_OR_EQUAL_TO) { return Relationship.LEQ; }/* w ww . j ava 2s. co m*/ throw new UnsupportedOperationException("Apache cannot handle this Relation: " + relation.toString()); }
From source file:uk.ac.tgac.metaopt.external.Apache.java
protected void addDecisionVariables(Collection<LinearConstraint> constraints, Problem problem) { List<Variable> variables = problem.getVariables(); // Add restriction constraint for (int i = 0; i < variables.size(); i++) { Variable var = variables.get(i); double[] coefficients = new double[variables.size()]; for (int j = 0; j < variables.size(); j++) { coefficients[j] = i == j ? 1.0 : 0.0; }// w w w . java 2 s.c om Bounds.BoundType boundType = var.getBounds().getBoundType(); if (boundType == Bounds.BoundType.FREE) { // Do nothing in this case } else if (boundType == Bounds.BoundType.LOWER) { constraints.add(new LinearConstraint(coefficients, Relationship.GEQ, var.getBounds().getLower())); } else if (boundType == Bounds.BoundType.UPPER) { constraints.add(new LinearConstraint(coefficients, Relationship.LEQ, var.getBounds().getUpper())); } else if (boundType == Bounds.BoundType.DOUBLE) { constraints.add(new LinearConstraint(coefficients, Relationship.GEQ, var.getBounds().getLower())); constraints.add(new LinearConstraint(coefficients, Relationship.LEQ, var.getBounds().getUpper())); } else if (boundType == Bounds.BoundType.FIXED) { constraints.add(new LinearConstraint(coefficients, Relationship.EQ, var.getBounds().getLower())); } else { throw new IllegalArgumentException("Unknown bound type encountered: " + boundType.toString()); } } }