Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Planning codelet #16

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "CST is the Cognitive Systems Toolkit, a toolkit for the construct

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '0.5.1'
version = '0.6.0'

repositories {
flatDir {
Expand Down
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Wed Sep 09 22:32:12 BRT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
72 changes: 72 additions & 0 deletions src/main/java/br/unicamp/cst/planning/PlanningCodelet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package br.unicamp.cst.planning;

import br.unicamp.cst.core.entities.Codelet;
import br.unicamp.cst.core.entities.Memory;
import br.unicamp.cst.core.exceptions.CodeletActivationBoundsException;

import java.util.Optional;

public abstract class PlanningCodelet extends Codelet {

private String id;

private Memory inputInitialState;

private Memory inputGoals;
private Memory inputActions;
private Memory inputTransitionFunctions;
private Memory inputPlanningRequest;

private Memory outputPlan;

public PlanningCodelet(String id) {
setId(id);
}

@Override
public void accessMemoryObjects() {
inputInitialState = Optional.ofNullable(inputGoals)
.orElse(getInput(PlanningMemoryNames.INPUT_INITIAL_STATE.toString()));

inputGoals = Optional.ofNullable(inputGoals)
.orElse(getInput(PlanningMemoryNames.INPUT_GOALS.toString()));

inputActions = Optional.ofNullable(inputActions)
.orElse(getInput(PlanningMemoryNames.INPUT_ACTIONS.toString()));

inputTransitionFunctions = Optional.ofNullable(inputTransitionFunctions)
.orElse(getInput(PlanningMemoryNames.INPUT_TRANSITION_FUNCTIONS.toString()));

inputPlanningRequest = Optional.ofNullable(inputPlanningRequest)
.orElse(getInput(PlanningMemoryNames.INPUT_PLANNING_REQUEST.toString()));

outputPlan = Optional.ofNullable(outputPlan)
.orElse(getInput(PlanningMemoryNames.OUTPUT_PLAN.toString()));
}

@Override
public void calculateActivation() {
try {
setActivation(0d);
} catch (CodeletActivationBoundsException e) {
e.printStackTrace();
}
}

@Override
public void proc() {
Optional.ofNullable(outputPlan).ifPresent(memory -> {
memory.setI(planning(inputInitialState, inputGoals, inputActions, inputTransitionFunctions, inputPlanningRequest).getI());
});
}

public abstract Memory planning(Memory currentState, Memory goals, Memory actions, Memory transitionFunctions, Memory planningRequest);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method planning has 5 arguments (exceeds 4 allowed). Consider refactoring.


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
10 changes: 10 additions & 0 deletions src/main/java/br/unicamp/cst/planning/PlanningMemoryNames.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package br.unicamp.cst.planning;

public enum PlanningMemoryNames {
INPUT_INITIAL_STATE,
INPUT_GOALS,
INPUT_ACTIONS,
INPUT_TRANSITION_FUNCTIONS,
INPUT_PLANNING_REQUEST,
OUTPUT_PLAN
}