24 package org.lightjason.agentspeak.action.builtin.graph;
27 import com.codepoetics.protonpack.StreamUtils;
28 import com.google.common.base.Function;
29 import edu.uci.ics.jung.graph.Graph;
38 import javax.annotation.Nonnegative;
39 import javax.annotation.Nonnull;
40 import java.util.Collections;
41 import java.util.List;
43 import java.util.stream.Collectors;
70 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
73 final List<ITerm> l_arguments =
CCommon.
flatten( p_argument ).collect( Collectors.toList() );
74 if ( l_arguments.size() < 3 )
77 final Map<Object, Number> l_weights = l_arguments.parallelStream()
80 .map(
ITerm::<Map<Object, Number>>raw )
81 .orElseGet( Collections::emptyMap );
83 final Number l_defaultvalue = StreamUtils.windowed( l_arguments.stream(), 2 )
85 && DEFAULTWEIGHT.equalsIgnoreCase( i.get( 0 ).<String>raw() )
89 .map( i -> i.get( 1 ).<Number>raw() )
92 final Function<Object, Number> l_weightfunction = e -> l_weights.getOrDefault( e, l_defaultvalue );
94 final List<ITerm> l_vertices = StreamUtils.windowed( l_arguments.stream(), 2 )
96 && DEFAULTWEIGHT.equalsIgnoreCase( i.get( 0 ).<String>raw() )
102 .orElseGet( Collections::emptyList );
104 if ( l_vertices.isEmpty() )
110 .map(
ITerm::<Graph<Object, Object>>raw )
111 .map( i -> this.
apply( l_vertices, i, l_weightfunction ) )
113 .forEach( p_return::add );
127 protected abstract Object
apply( @Nonnull
final List<ITerm> p_vertices, @Nonnull
final Graph<Object, Object> p_graph,
128 @Nonnull
final Function<Object, Number> p_weightfunction );
base class of build-in actions for setting name by package/classname (without prefix character) ...
abstract class to define path / distance graph algorithms
static final String DEFAULTWEIGHT
default weight field
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
common structure for execution definition
final int minimalArgumentNumber()
minimum number of arguments
execution context with local data
static Stream< ITerm > flatten( @Nonnull final Collection<? extends ITerm > p_terms)
flat term-in-term collection into a straight term list
static< T > boolean rawvalueAssignableTo( @Nonnull final T p_value, @Nonnull final Class<?>... p_class)
checks a term value for assignable class
result for an immutable fuzzy value
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
abstract Object apply( @Nonnull final List< ITerm > p_vertices, @Nonnull final Graph< Object, Object > p_graph, @Nonnull final Function< Object, Number > p_weightfunction)
apply function
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
static final long serialVersionUID
serial id
term structure for simple datatypes