Skip to content

Commit

Permalink
feature: add goal created in the design level
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-elena committed Jun 4, 2024
1 parent 6d8b82c commit a6db311
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 37 deletions.
7 changes: 3 additions & 4 deletions src/component/event/EventMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import NewSpeechActMessage from "./implementation/speechActMessageEvent/NewSpeec
import SelectedMessage from "./implementation/speechActMessageEvent/SelectedMessage";
import SendMessage from "./implementation/speechActMessageEvent/SendMessage";
import PlanSelected from "./implementation/goalEvent/PlanSelected";
import NewDesire from "./design/NewDesire";
import DesireCommitted from "./design/DesireCommitted";
import DesireRemoved from "./design/DesireRemoved";
import ExecutedAction from "./design/ExecutedAction";
import NewBelief from "./design/NewBelief";
import SelectPlan from "./design/SelectPlan";
import BDIBeliefRemoved from "./design/BeliefRemoved";
import BDIGoalCreated from "./design/BDIGoalCreated";

const EventMapping = {
ExecutedDeed: {implementation: <ExecutedDeed/>, design: <ExecutedAction/>},
Expand All @@ -42,11 +41,11 @@ const EventMapping = {
BeliefFromSrcAdded: {implementation: <BeliefFromSrcAdded/>, design: <></>},
BeliefFromSrcRemoved: {implementation: <BeliefFromSrcRemoved/>, design: <></>},
BeliefRemoved: {implementation: <BeliefRemoved/>, design: <BDIBeliefRemoved/>},
GoalCreated: {implementation: <GoalCreated/>, design: <NewDesire/>},
GoalCreated: {implementation: <GoalCreated/>, design: <BDIGoalCreated/>},
GoalRemoved: {implementation: <GoalRemoved/>, design: <DesireRemoved/>},
GoalSuspended: {implementation: <GoalSuspended/>, design: <></>},
PlanSelected: {implementation: <PlanSelected/>, design: <></>},
IntentionCreated: {implementation: <IntentionCreated/>, design: <DesireCommitted/>},
IntentionCreated: {implementation: <IntentionCreated/>, design: <></>}, //todo
IntentionRemoved: {implementation: <IntentionRemoved/>, design: <></>},
IntentionSuspended: {implementation: <IntentionSuspended/>, design: <></>},
IntentionWaiting: {implementation: <IntentionWaiting/>, design: <></>},
Expand Down
14 changes: 14 additions & 0 deletions src/component/event/design/BDIGoalCreated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import DesireCommitted from "./DesireCommitted";
import NewDesire from "./NewDesire";

function BDIGoalCreated(props) {
return (
<div>
<NewDesire log={props.log} event={props.event} filter={props.filter} level={props.level}/>
<div className={"mb-5"}/>
<DesireCommitted log={props.log} event={props.event} filter={props.filter} level={props.level}/>
</div>
)
}

export default BDIGoalCreated;
89 changes: 56 additions & 33 deletions src/component/event/design/DesireCommitted.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,70 @@
import React from "react";
import Event from "../Event";
import {agentState, getIntentionReason} from "../../../model/agentState";
import {Level} from "../../../model/Level";

function DesireCommitted(props) {

const type = "Desire committed";

const intention = props.event.message.event
const desire = intention.intentionInfo.trigger
let selectedPlan = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "SelectPlanEvent" && e.message.event.selectedPlan.trigger === desire)
const planSelected = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "PlanSelected" && e.message.event.goalInfo.goalFunctor === desire)
const type = "Desire committed"
const goalInfo = props.event.message.event.goalInfo
const goal = goalInfo.goalFunctor
const description = "I committed to desire " + goal + " and it becomes a goal"
const source = goalInfo.source.value
const intention = goalInfo.intention.value
const explanation = props.event
let parentDesire

const explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.goalFunctor === desire)
if (source && source.includes("self")) {
if (intention && intention.intendedMeansInfo.length > 0) {
console.log(intention.intendedMeansInfo)
parentDesire = "Goal " + goal + " is a goal created from " + intention.intendedMeansInfo[0].trigger
}
}

if (intention && selectedPlan && planSelected) {
selectedPlan = selectedPlan.message.event.selectedPlan
const context = selectedPlan.context ? " because I believe " + selectedPlan.context.replace("&", "and").replace("|", "or") : ""
const body = selectedPlan.body ? "Plan body: " + selectedPlan.body : ""
const id = intention.intentionInfo.id
const description = "I committed to desire " + desire + context + ", and it became a new intention int-" + id + "-" + intention.intentionInfo.trigger
return (
<Event type={type} description={description} info={parentDesire}
timestamp={props.event.timestamp}
filter={props.filter}
explanation={explanation}
log={props.log}
level={Level.DESIGN}/>
)

let reason = getIntentionReason(desire, intention.intentionInfo)
let parentDesire = reason ? ["Intention int-" + id + "-" + desire + " is an intention " + reason, <br/>] : []

if (agentState.intention[id]) {
agentState.intention[id].push(desire)
} else {
agentState.intention[id] = [desire]
}

return (
<div>
<Event type={type} description={description} info={[...parentDesire, body]}
timestamp={props.event.timestamp}
filter={props.filter}
explanation={explanation}
log={props.log}
level={Level.DESIGN}/>
</div>

)
}
// const type = "Desire committed";
//
// const intention = props.event.message.event
// const desire = intention.intentionInfo.trigger
// let selectedPlan = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "SelectPlanEvent" && e.message.event.selectedPlan.trigger === desire)
// const planSelected = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "PlanSelected" && e.message.event.goalInfo.goalFunctor === desire)
//
// const explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.goalFunctor === desire)
//
// if (intention && selectedPlan && planSelected) {
// selectedPlan = selectedPlan.message.event.selectedPlan
// const context = selectedPlan.context ? " because I believe " + selectedPlan.context.replace("&", "and").replace("|", "or") : ""
// const body = selectedPlan.body ? "Plan body: " + selectedPlan.body : ""
// const id = intention.intentionInfo.id
// const description = "I committed to desire " + desire + context + ", and it became a new intention int-" + id + "-" + intention.intentionInfo.trigger
//
// let reason = getIntentionReason(desire, intention.intentionInfo)
// let parentDesire = reason ? ["Intention int-" + id + "-" + desire + " is an intention " + reason, <br/>] : []
//
// if (agentState.intention[id]) {
// agentState.intention[id].push(desire)
// } else {
// agentState.intention[id] = [desire]
// }
//
// return (
// <Event type={type} description={description} info={[...parentDesire, body]}
// timestamp={props.event.timestamp}
// filter={props.filter}
// explanation={explanation}
// log={props.log}
// level={Level.DESIGN}/>
// )
// }
}

export default DesireCommitted;

0 comments on commit a6db311

Please sign in to comment.