24 package org.lightjason.agentspeak.action.builtin.math.linearprogram;
26 import com.codepoetics.protonpack.StreamUtils;
27 import org.apache.commons.lang3.tuple.Pair;
28 import org.apache.commons.math3.optim.linear.LinearConstraint;
29 import org.apache.commons.math3.optim.linear.LinearObjectiveFunction;
36 import javax.annotation.Nonnegative;
37 import javax.annotation.Nonnull;
38 import java.util.Collection;
39 import java.util.List;
40 import java.util.stream.Collectors;
77 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return )
79 final List<ITerm> l_arguments =
CCommon.flatten( p_argument ).collect( Collectors.toList() );
82 final List<Number> l_lhs = StreamUtils.takeWhile( l_arguments.stream().skip( 1 ), i -> !
CCommon.rawvalueAssignableTo( i, String.class ) )
83 .map(
ITerm::<Number>raw )
84 .collect( Collectors.toList() );
86 final List<ITerm> l_rhs = l_arguments.stream()
87 .skip( l_lhs.size() + 1 )
88 .collect( Collectors.toList() );
91 if ( ( l_lhs.size() < 2 ) || ( l_rhs.size() < 3 ) || ( !
CCommon.rawvalueAssignableTo( l_rhs.get( 0 ), String.class ) ) )
95 l_arguments.get( 0 ).<Pair<LinearObjectiveFunction, Collection<LinearConstraint>>>raw().getRight().add(
100 .limit( l_lhs.size() - 1 )
101 .mapToDouble( Number::doubleValue )
105 l_lhs.get( l_lhs.size() - 1 )
113 .limit( l_rhs.size() - 1 )
115 .map(
ITerm::<Number>raw )
116 .mapToDouble( Number::doubleValue )
120 l_rhs.get( l_rhs.size() - 1 )
final Relationship getRelation( @Nonnull final String p_symbol)
returns the enum of a relationship by a string value
abstract class for constraint actions
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
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
add a linear equation constraint to the LP.
execution context with local data
static final long serialVersionUID
serial id
result for an immutable fuzzy value
class for any helper calls
final int minimalArgumentNumber()
minimum number of arguments