-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Stock
committed
Aug 16, 2013
0 parents
commit da4819b
Showing
8 changed files
with
995 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.cproject | ||
.project | ||
.pydevproject | ||
.settings | ||
.classpath | ||
.classpath-generated | ||
.project-generated | ||
ros.properties | ||
dependencies.xml | ||
cmake_install.cmake | ||
build/ | ||
bin/ | ||
msg_gen/ | ||
srv_gen/ | ||
*.pyc | ||
.gradle/ | ||
.svn | ||
*.bak | ||
CMakeFiles/ | ||
*~ | ||
CMakeCache.txt | ||
Makefile.ros |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'eclipse' | ||
|
||
// The Maven plugin is only required if your package is used as a library. | ||
apply plugin: 'maven' | ||
|
||
// The Application plugin and mainClassName attribute are only required if | ||
// your package is used as a binary. | ||
apply plugin: 'application' | ||
// The main class that will be executed when you do 'gradle run' | ||
mainClassName = 'TestSimpleSTNPlanner' | ||
|
||
sourceCompatibility = 1.6 | ||
targetCompatibility = 1.6 | ||
|
||
repositories { | ||
|
||
mavenCentral() | ||
mavenLocal() | ||
|
||
} | ||
|
||
version = '0.0.0-SNAPSHOT' | ||
group = 'metacsp_htn_planner' | ||
|
||
dependencies { | ||
|
||
//compile fileTree(dir: 'lib', include: '**/*.jar') | ||
|
||
// This pulls in the meta-csp-framework jar | ||
compile 'org.metacsp:meta-csp-framework:1.0.175' | ||
//compile 'meta_csp_framework:meta_csp_framework:0.0.0-SNAPSHOT' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package simpleSTNPlanner; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.metacsp.framework.ConstraintNetwork; | ||
import org.metacsp.framework.Variable; | ||
import org.metacsp.meta.simplePlanner.InvalidActivityException; | ||
import org.metacsp.multi.activity.Activity; | ||
import org.metacsp.multi.activity.ActivityNetworkSolver; | ||
import org.metacsp.multi.allenInterval.AllenIntervalConstraint; | ||
|
||
public abstract class PlanReportroryItem { | ||
|
||
protected String head; | ||
protected AllenIntervalConstraint[] requirementConstraints; | ||
protected String[] requirementActivities; | ||
|
||
public PlanReportroryItem(String head, | ||
AllenIntervalConstraint[] requirementConstraints, | ||
String[] requirementActivities) { | ||
this.head = head; | ||
if (requirementActivities != null) { | ||
for (String a : requirementActivities) { | ||
if (a.equals(head)) throw new InvalidActivityException(a); | ||
} | ||
} | ||
this.requirementConstraints = requirementConstraints; | ||
this.requirementActivities = requirementActivities; | ||
} | ||
|
||
public String getHead() { | ||
return head; | ||
} | ||
|
||
public AllenIntervalConstraint[] getRequirementConstraints() { | ||
return requirementConstraints; | ||
} | ||
|
||
public String[] getRequirementActivities() { | ||
return requirementActivities; | ||
} | ||
|
||
public String toString() { | ||
String ret = ""; | ||
if (requirementActivities != null) { | ||
for (int i = 0; i < requirementActivities.length; i++) { | ||
ret += head + " " + Arrays.toString(requirementConstraints[i].getTypes()) + " " + Arrays.toString(requirementConstraints[i].getBounds()) + " " + requirementActivities[i]; | ||
if (i != requirementActivities.length-1) ret += "\n"; | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
public String getHeadComponent() { | ||
return head.substring(0, head.indexOf("::")); | ||
} | ||
|
||
public String getHeadSymbol() { | ||
return head.substring(head.indexOf("::")+2, head.length()); | ||
} | ||
|
||
/** | ||
* Checks if an Operator can be applied. | ||
* It checks the operator's name and its preconditions. | ||
* @return | ||
*/ | ||
public boolean checkApplicability(Activity currentActivity, Variable[] activeVariables) { | ||
String currentActivitySymbolicDomain = currentActivity.getSymbolicVariable().getSymbols()[0]; | ||
String opHeadComponent = getHeadComponent(); | ||
String opHeadSymbol = getHeadSymbol(); | ||
// check if operator matches the activity | ||
if (opHeadComponent.equals(currentActivity.getComponent())) { | ||
if (currentActivitySymbolicDomain.contains(opHeadSymbol)) { | ||
return checkRequirements(activeVariables); | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Goes through all the requirementActivities and checks whether they exist in the network and have the marking ACTIVE. | ||
*/ | ||
public boolean checkRequirements(Variable[] activeVariables) { | ||
if (this.requirementActivities != null) { | ||
for (String opTail : this.requirementActivities) { | ||
if (searchActivity(opTail, activeVariables) < 0) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Searches for an Activity in an Array of Variables by its String. | ||
* @param activityString | ||
* @param vars Array of Variables to search in. | ||
* @return Index of the matching Variable. | ||
*/ | ||
public static int searchActivity(String activityString, Variable[] vars) { | ||
if (vars != null) { | ||
String tailComponent = activityString.substring(0, activityString.indexOf("::")); | ||
String tailSymbol = activityString.substring(activityString.indexOf("::")+2, activityString.length()); | ||
for (int i = 0; i < vars.length; i++) { | ||
Activity var = (Activity)vars[i]; | ||
if (tailComponent.equals(var.getComponent())) { | ||
String varSymbolicDomain = var.getSymbolicVariable().getSymbols()[0]; | ||
if (varSymbolicDomain.contains(tailSymbol)) { | ||
return i; | ||
} | ||
} | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
public abstract ConstraintNetwork expand(Activity problematicActivity, | ||
ActivityNetworkSolver groundSolver, | ||
Variable[] activeVariables); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2010-2013 Federico Pecora <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
******************************************************************************/ | ||
package simpleSTNPlanner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Vector; | ||
|
||
import org.metacsp.meta.symbolsAndTime.Schedulable; | ||
import org.metacsp.multi.activity.Activity; | ||
import org.metacsp.multi.activity.ActivityNetworkSolver; | ||
import org.metacsp.multi.allenInterval.AllenIntervalConstraint; | ||
import org.metacsp.framework.Constraint; | ||
import org.metacsp.framework.ConstraintNetwork; | ||
import org.metacsp.framework.ValueOrderingH; | ||
import org.metacsp.framework.Variable; | ||
import org.metacsp.framework.VariableOrderingH; | ||
import org.metacsp.framework.VariablePrototype; | ||
import org.metacsp.framework.meta.MetaConstraint; | ||
import org.metacsp.framework.meta.MetaVariable; | ||
|
||
public class SimpleSTNDomain extends MetaConstraint { | ||
|
||
|
||
/** | ||
* | ||
*/ | ||
private static final long serialVersionUID = -7226230284206806067L; | ||
|
||
private Vector<SimpleSTNOperator> operators; | ||
private Vector<SimpleSTNMethod> methods; | ||
|
||
private String name; | ||
|
||
public enum markings {ACTIVE, CLOSED, EXECUTED, PLANNED, NEW, UNJUSTIFIED, JUSTIFIED}; | ||
|
||
|
||
public SimpleSTNDomain(String domainName) { | ||
super(null, null); | ||
this.name = domainName; | ||
this.operators = new Vector<SimpleSTNOperator>(); | ||
this.methods = new Vector<SimpleSTNMethod>(); | ||
} | ||
|
||
public void addOperator(SimpleSTNOperator r) { | ||
operators.add(r); | ||
} | ||
|
||
public SimpleSTNOperator[] getOperators() { | ||
return operators.toArray(new SimpleSTNOperator[operators.size()]); | ||
} | ||
|
||
public SimpleSTNMethod[] getMethods() { | ||
return methods.toArray(new SimpleSTNMethod[methods.size()]); | ||
} | ||
|
||
public void addMethod(SimpleSTNMethod m) { | ||
this.methods.add(m); | ||
} | ||
|
||
/** | ||
* Returns all Activities that have the marking NEW. | ||
*/ | ||
@Override | ||
public ConstraintNetwork[] getMetaVariables() { | ||
ActivityNetworkSolver groundSolver = (ActivityNetworkSolver)this.metaCS.getConstraintSolvers()[0]; | ||
Vector<ConstraintNetwork> ret = new Vector<ConstraintNetwork>(); | ||
// for every variable that is marked as NEW an ActivityNetwork is built | ||
// this becomes a task | ||
for (Variable task : groundSolver.getVariables()) { | ||
if (task.getMarking() != null && task.getMarking().equals(markings.NEW)) { | ||
ConstraintNetwork nw = new ConstraintNetwork(null); | ||
nw.addVariable(task); | ||
ret.add(nw); | ||
} | ||
} | ||
return ret.toArray(new ConstraintNetwork[ret.size()]); | ||
} | ||
|
||
/** | ||
* Filters for Variables with the marking ACTIVE. | ||
*/ | ||
private Variable[] getActiveVariables(Variable[] vars) { | ||
ArrayList<Variable> ret = new ArrayList<Variable>(); | ||
for (Variable var: vars) { | ||
if (var.getMarking() == markings.ACTIVE) { | ||
ret.add(var); | ||
} | ||
} | ||
return ret.toArray(new Variable[ret.size()]); | ||
} | ||
|
||
@Override | ||
public ConstraintNetwork[] getMetaValues(MetaVariable metaVariable, int initialTime) { | ||
return getMetaValues(metaVariable); | ||
} | ||
|
||
@Override | ||
public ConstraintNetwork[] getMetaValues(MetaVariable metaVariable) { | ||
Vector<ConstraintNetwork> retPossibleConstraintNetworks = new Vector<ConstraintNetwork>(); | ||
ConstraintNetwork problematicNetwork = metaVariable.getConstraintNetwork(); | ||
Activity currentActivity = (Activity)problematicNetwork.getVariables()[0]; | ||
|
||
ActivityNetworkSolver groundSolver = (ActivityNetworkSolver)this.metaCS.getConstraintSolvers()[0]; | ||
Variable[] activeVariables = getActiveVariables(groundSolver.getVariables()); | ||
|
||
for (SimpleSTNOperator op : operators) { | ||
if (op.checkApplicability(currentActivity, activeVariables)) { | ||
ConstraintNetwork newResolver = op.expand(currentActivity, groundSolver, activeVariables); | ||
retPossibleConstraintNetworks.add(newResolver); | ||
} | ||
} | ||
for (SimpleSTNMethod m : methods) { | ||
if (m.checkApplicability(currentActivity, activeVariables)) { | ||
ConstraintNetwork newResolver = m.expand(currentActivity, groundSolver, activeVariables); | ||
retPossibleConstraintNetworks.add(newResolver); | ||
} | ||
} | ||
|
||
if (!retPossibleConstraintNetworks.isEmpty()) return retPossibleConstraintNetworks.toArray(new ConstraintNetwork[retPossibleConstraintNetworks.size()]); | ||
// ConstraintNetwork nullActivityNetwork = new ConstraintNetwork(null); | ||
// return new ConstraintNetwork[] {nullActivityNetwork}; // TODO does this make sense or just return null??? | ||
return null; // no solution found | ||
} | ||
|
||
@Override | ||
public void markResolvedSub(MetaVariable con, ConstraintNetwork metaValue) { | ||
con.getConstraintNetwork().getVariables()[0].setMarking(markings.EXECUTED); | ||
} | ||
|
||
@Override | ||
public void draw(ConstraintNetwork network) { | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SimpleDomain " + this.name; | ||
} | ||
|
||
@Override | ||
public String getEdgeLabel() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Object clone() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isEquivalent(Constraint c) { | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.