24 package org.lightjason.agentspeak.action.builtin.math.linearprogram;
26 import org.apache.commons.lang3.tuple.Pair;
27 import org.apache.commons.math3.optim.MaxIter;
28 import org.apache.commons.math3.optim.OptimizationData;
29 import org.apache.commons.math3.optim.PointValuePair;
30 import org.apache.commons.math3.optim.linear.LinearConstraint;
31 import org.apache.commons.math3.optim.linear.LinearConstraintSet;
32 import org.apache.commons.math3.optim.linear.LinearObjectiveFunction;
33 import org.apache.commons.math3.optim.linear.NonNegativeConstraint;
34 import org.apache.commons.math3.optim.linear.SimplexSolver;
35 import org.apache.commons.math3.optim.nonlinear.scalar.GoalType;
44 import javax.annotation.Nonnegative;
45 import javax.annotation.Nonnull;
46 import java.util.Arrays;
47 import java.util.Collection;
48 import java.util.LinkedList;
49 import java.util.List;
50 import java.util.Objects;
97 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return )
101 final List<OptimizationData> l_settings =
new LinkedList<>();
103 final Pair<LinearObjectiveFunction, Collection<LinearConstraint>> l_default = p_argument.get( 0 ).raw();
104 l_settings.add( l_default.getLeft() );
105 l_settings.add(
new LinearConstraintSet( l_default.getRight() ) );
107 p_argument.subList( 1, p_argument.size() ).stream()
110 if (
CCommon.rawvalueAssignableTo( i, Number.class ) )
111 return new MaxIter( i.raw() );
113 if (
CCommon.rawvalueAssignableTo( i, String.class ) )
114 switch ( i.<String>raw().trim().toLowerCase() )
117 return new NonNegativeConstraint(
true );
119 return GoalType.MAXIMIZE;
121 return GoalType.MINIMIZE;
129 .filter( Objects::nonNull )
130 .forEach( l_settings::add );
133 final SimplexSolver l_lp =
new SimplexSolver();
134 final PointValuePair l_result = l_lp.optimize( l_settings.toArray(
new OptimizationData[l_settings.size()] ) );
137 p_return.add(
CRawTerm.
from( l_result.getPoint().length ) );
138 Arrays.stream( l_result.getPoint() ).boxed().map(
CRawTerm::from ).forEach( p_return::add );
base class of build-in actions for setting name by package/classname (without prefix character) ...
static final long serialVersionUID
serial id
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
solves the linear program and returns the solution.
execution context with local data
final IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
result for an immutable fuzzy value
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
class for any helper calls
final int minimalArgumentNumber()
minimum number of arguments
term structure for simple datatypes