Skip to content

Commit

Permalink
Added TimeSteppedEnvironment for better oerview and minor fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartisan committed Jun 14, 2017
1 parent 2c9b1e1 commit 0708661
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/asl/emotions.asl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ happiness(0)[target([])].
+!rewarded(L) : true <- !!rewarded(L).

// +relativised commitment
-happiness(X) : ~happiness(Y) & Y>9 <-
-happiness(X) : happiness(Y) & em_threshold(Z) & Y<=Z <-
-rewarded(L);
-self(happy);
.succeed_goal(rewarded(L)).
Expand Down Expand Up @@ -104,7 +104,7 @@ happiness(0)[target([])].
+!punished(L) : true <- !!punished(L).

// + relativised commitment
-anger(X) : ~anger(Y) & Y>9 <-
-anger(X) : anger(Y) & em_threshold(Z) & Y<=Z <-
-self(angry);
.add_plan(helpfullness);
.succeed_goal(punished(L)).
2 changes: 1 addition & 1 deletion src/asl/general_animal.asl
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ default_activity(farm_work).
@communality
+!X[_] : self(communal) & is_work(X) & not already_asked(X) <-
?animals(Animals);
+already_asked(X);
for (.member(Animal, Animals)) {
.print("Asking ", Animal, " to help with ", X)
.send(Animal, achieve, help_with(X));
+asking(X, Animal);
}
+already_asked(X);
.suspend(X);
!X.

Expand Down
5 changes: 2 additions & 3 deletions src/java/little_red_hen/jason/FarmEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import jason.asSyntax.Literal;
import jason.asSyntax.Structure;
import jason.environment.Environment;
import jason.runtime.MASConsoleGUI;
import jason.environment.TimeSteppedEnvironment;
import jason.util.Pair;
import little_red_hen.Agent;
import little_red_hen.FarmModel;
import little_red_hen.Launcher;
import little_red_hen.PlotGraph;

public class FarmEnvironment extends Environment {
public class FarmEnvironment extends TimeSteppedEnvironment {

static Logger logger = Logger.getLogger(FarmEnvironment.class.getName());

Expand Down
38 changes: 38 additions & 0 deletions src/java/little_red_hen/jason/PlotAwareAgArch.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package little_red_hen.jason;

import java.util.Iterator;

import jason.architecture.AgArch;
import jason.asSemantics.Message;
import jason.asSemantics.Unifier;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.Literal;
import jason.asSyntax.Term;
import jason.asSyntax.VarTerm;
import jason.bb.BeliefBase;
import little_red_hen.PlotGraph;

public class PlotAwareAgArch extends AgArch {

static int DECAY_RATE = 1;

@Override
public void sendMsg(Message m) throws Exception {
Expand All @@ -14,5 +24,33 @@ public void sendMsg(Message m) throws Exception {
// plot it in the graph
PlotGraph.getPlotListener().addRequest(m.getSender(), m.getReceiver(), m.getPropCont().toString());
}
//
// @Override
// public void reasoningCycleStarting() {
// BeliefBase belief_base = getTS().getAg().getBB();
//
// // get names of emotion scales
// Iterator<Literal> em_scale_it = belief_base.getCandidateBeliefs(Literal.parseLiteral("emotion_scale(X)"),
// new Unifier());
//
// //for each scale extract literal of form:
// // em_scale(Value)[target(_), source(_)]
// while (em_scale_it.hasNext()) {
// Literal em_scale_general = em_scale_it.next(); //has no value or annotations attached
// Literal emotion_term = Literal.parseLiteral(em_scale_general.getTerm(0).toString());
//
// Literal em_scale_concr = belief_base.getCandidateBeliefs(emotion_term, new Unifier()).next();
// int value = Integer.valueOf(em_scale_concr.getTerm(0).toString());
//
// if (value > 0) {
// int new_val = Integer.min(value-DECAY_RATE, 0);
// em_scale_concr.setTerm(0, ASSyntax.parseNumber(String.valueOf(new_val)));
//// belief_base.remove(em_scale_general);
//// belief_base.add(em_scale_concr);
// }
// }
//
// super.reasoningCycleStarting();
// }

}

0 comments on commit 0708661

Please sign in to comment.