Skip to content

Commit

Permalink
handling recursion
Browse files Browse the repository at this point in the history
  • Loading branch information
anacleto85 committed May 11, 2024
1 parent 1056067 commit ae37650
Show file tree
Hide file tree
Showing 512 changed files with 61 additions and 90 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .idea/.gitignore
100644 → 100755
Empty file.
Empty file modified .idea/compiler.xml
100644 → 100755
Empty file.
Empty file modified .idea/jarRepositories.xml
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified .idea/libraries/Maven__dk_brics_automaton_automaton_1_11_8.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__junit_junit_4_13_2.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__net_sf_trove4j_trove4j_3_0_3.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_antlr_ST4_4_0_8.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_antlr_antlr_3_5_2.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_antlr_antlr_runtime_3_5_2.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_choco_solver_choco_sat_1_0_2.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_choco_solver_choco_solver_4_0_2.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_choco_solver_cutoffseq_1_0_2.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml
100644 → 100755
Empty file.
Empty file.
Empty file modified .idea/libraries/Maven__org_jfree_jcommon_1_0_23.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_jfree_jfreechart_1_0_19.xml
100644 → 100755
Empty file.
Empty file modified .idea/libraries/Maven__org_mongodb_mongo_java_driver_3_12_9.xml
100644 → 100755
Empty file.
Empty file modified .idea/misc.xml
100644 → 100755
Empty file.
Empty file modified .idea/modules.xml
100644 → 100755
Empty file.
Empty file modified .idea/vcs.xml
100644 → 100755
Empty file.
Empty file modified .settings/org.eclipse.jdt.core.prefs
100644 → 100755
Empty file.
Empty file modified .settings/org.eclipse.m2e.core.prefs
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified LICENSE.txt
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified dependency-reduced-pom.xml
100644 → 100755
Empty file.
Empty file modified etc/deliberative.properties
100644 → 100755
Empty file.
Empty file modified etc/executive.properties
100644 → 100755
Empty file.
Empty file modified pom.xml
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ public boolean equals(Object obj) {
@Override
public String toString() {
// JSON style object description
return "{ id: " + this.id+ ", label: \"" + this.label + "\", component: \"" + this.component.getName() + "\" }";
return "{\"label\": \"" + this.label + "\"}";
}
}
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
105 changes: 37 additions & 68 deletions src/main/java/it/cnr/istc/pst/platinum/ai/framework/domain/component/sv/StateVariable.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package it.cnr.istc.pst.platinum.ai.framework.domain.component.sv;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -129,89 +128,59 @@ public List<ComponentValue> getDirectSuccessors(ComponentValue value) {
* @param target
* @return
*/
public List<ValuePath> getPaths(ComponentValue source, ComponentValue target)
{
// list of all acyclic paths that start from the source value and end to the target value
List<ValuePath> result = new ArrayList<>();
// check the case in which the source value is equal to the target value
if (source.equals(target))
{
// just start the search starting from the direct successors of the current value
for (ComponentValue successor : this.getDirectSuccessors(source))
{
// just avoid reflexive transition (that should not be allowed in the domain specification)
if (!source.equals(successor)) {
// get list of paths
for (ValuePath path : this.computePaths(successor, target, new ArrayList<>())) {
// add the source value in front of the path
path.addFirstStep(source);
// add the path to the result list
result.add(path);
}
}
}
}
else {
// call recursive function to compute all acyclic paths between state variable values
result = this.computePaths(source, target, new ArrayList<>());
}
public List<ValuePath> getPaths(ComponentValue source, ComponentValue target) {

// sort paths according to their length
Collections.sort(result);
// list of all acyclic paths that start from the source value and end to the target value
List<ValuePath> paths = new ArrayList<>();
// initialize value path
ValuePath path = new ValuePath();
path.addLastStep(source);
// call recursive method to unfold state variable description and build possible paths
this.computePaths(source, target, path, paths);
// get the result list
return result;
return paths;
}

/**
*
* @param source
* @param target
* @param visited
* @return
*/
private List<ValuePath> computePaths(ComponentValue source, ComponentValue target, List<ComponentValue> visited)
{
// result list
List<ValuePath> result = new ArrayList<>();
private void computePaths(ComponentValue source, ComponentValue target, ValuePath path, List<ValuePath> paths) { //, List<ComponentValue> visited) {

// compare source value and target value
if (source.equals(target)) {
// create value path
ValuePath path = new ValuePath();
// add last step
path.addLastStep(source);
// add to result
result.add(path);
}
else
{
// add current node to visited list
visited.add(source);
// navigate the state variable towards the target value
for (ComponentValue value : this.getDirectSuccessors(source))
{
// check cycle
if (!visited.contains(value))
{
// get partial paths found through recursive call
List<ValuePath> paths = this.computePaths(value, target, visited);
// aggregate and build the result
for (ValuePath path : paths)
{
// add current value the current (partial) path
path.addFirstStep(source);
// add the current (partial) path to the result list
result.add(path);
}
// add path to the paths
paths.add(path);

} else {

// add source to the path
// path.addLastStep(source);
// check successors of the (current) source node
for (ComponentValue successor : this.getDirectSuccessors(source)) {

// check if the successor is contained in the current value path to avoid cycles
if (!path.contains(successor)) {
// create an alternative path for each successor
ValuePath otherPath = new ValuePath(path.getSteps());

// add source
path.addLastStep(source);
// add successor
otherPath.addLastStep(successor);
// recursive call
this.computePaths(successor, target, otherPath, paths);

}
// else {
//
// // log something
// System.out.println("\n>>>>> Source [" + source.getLabel() + "] Successor [" + successor.getLabel()+ "], Target [" + target.getLabel() + "]\n--> skip path: " + path + "\n");
// }
}

// remove visited value
visited.remove(source);
}

// get list of paths
return result;
}

/**
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
44 changes: 23 additions & 21 deletions ...ork/microkernel/resolver/timeline/behavior/planning/TimelineBehaviorPlanningResolver.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package it.cnr.istc.pst.platinum.ai.framework.microkernel.resolver.timeline.behavior.planning;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -328,33 +329,34 @@ protected List<Flaw> doFindFlaws()
*
*/
@Override
protected void doComputeFlawSolutions(Flaw flaw)
throws UnsolvableFlawException
{
protected void doComputeFlawSolutions(Flaw flaw) throws UnsolvableFlawException {

// get the gap
Gap gap = (Gap) flaw;
// check gap type
switch (gap.getGapType())
{
switch (gap.getGapType()) {

// incomplete time-line
case INCOMPLETE_TIMELINE :
{
case INCOMPLETE_TIMELINE : {
// check all (acyclic) paths among tokens
List<ValuePath> paths = this.component.getPaths(
gap.getLeftDecision().getValue(),
gap.getRightDecision().getValue());

// sort paths
Collections.sort(paths);
// check found solutions
if (paths.isEmpty()) {
// not gap completion found between the two tokens
throw new UnsolvableFlawException("Not gap completion found:\n"
+ "- gap: " + gap + "\n");
}
else
{
} else {

// compute a solution for each possible value path
for (ValuePath path : paths)
{
for (ValuePath path : paths) {
// get steps
List<ComponentValue> steps = path.getSteps();
// remove the source and destination values from the path
Expand All @@ -370,11 +372,11 @@ protected void doComputeFlawSolutions(Flaw flaw)
List<Relation> rCreated = new ArrayList<>();
List<Relation> rActivated = new ArrayList<>();

try
{
try {
// check solution feasibility
if (solution.getPath().isEmpty())
{
if (solution.getPath().isEmpty()) {
// direct token transition between active decisions
Decision reference = solution.getLeftDecision();
Decision target = solution.getRightDecision();
Expand All @@ -401,17 +403,17 @@ protected void doComputeFlawSolutions(Flaw flaw)
rActivated.add(pRel);
}
}
}
else
{
} else {
// create the list of the decisions
List<Decision> transition = new ArrayList<>();
// add the gap-left decision
transition.add(solution.getLeftDecision());

// intermediate values and related relations can be activated since no synchronization is entailed
for (ComponentValue value : solution.getPath())
{
for (ComponentValue value : solution.getPath()) {
// create parameters' labels
String[] labels = new String[value.getNumberOfParameterPlaceHolders()];
for (int index = 0; index < labels.length; index++) {
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit ae37650

Please sign in to comment.