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
80 changes: 80 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,80 @@
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 inputObservations;

private Memory inputGoals;

private Memory inputProceduralMemory;

private Memory inputTransitionFunctions;

private Memory inputPlanningRequest;

private Memory outputPlan;

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

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

inputObservations = Optional.ofNullable(inputObservations)
.orElse(getInput(PlanningMemoryNames.INPUT_OBSERVATIONS.toString()));

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

inputProceduralMemory = Optional.ofNullable(inputProceduralMemory)
.orElse(getInput(PlanningMemoryNames.INPUT_PROCEDURAL_MEMORY.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, inputObservations, inputGoals, inputProceduralMemory, inputTransitionFunctions, inputPlanningRequest).getI());
});
}

public abstract Memory planning(Memory initialState, Memory observations, Memory goals, Memory proceduralMemory, 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 6 arguments (exceeds 4 allowed). Consider refactoring.


public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}
}
11 changes: 11 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,11 @@
package br.unicamp.cst.planning;

public enum PlanningMemoryNames {
INPUT_INITIAL_STATE,
INPUT_OBSERVATIONS,
INPUT_GOALS,
INPUT_PROCEDURAL_MEMORY,
INPUT_TRANSITION_FUNCTIONS,
INPUT_PLANNING_REQUEST,
OUTPUT_PLAN
}