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

Bn updates and tests #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 118 additions & 73 deletions src/main/java/br/unicamp/cst/behavior/bn/Behavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public abstract class Behavior extends Codelet
private double activationMA=0;

private WorkingStorage ws;

//For test variables
private double inputfromstate;
private double inputfromgoals;
private double spreadbw;
private double spreadfw;
private double activationWhenActive;

public Behavior(WorkingStorage ws,GlobalVariables globalVariables)
{
Expand Down Expand Up @@ -121,7 +128,7 @@ public Behavior(WorkingStorage ws,GlobalVariables globalVariables)
*/
public void proc()
{

activationWhenActive = this.getActivation();
retrieveGoals(); // This should be done often because goals might change over time
retrieveState(); // This should be done often because world state might change over time
spreadActivation();
Expand Down Expand Up @@ -405,11 +412,11 @@ private void spreadActivation()
if(!this.isActive()){ //If active, it should remain at zero
double activation = 0;
// TODO this can be optimized, I could get all this information with only one method (this would iterate only once through the coalition list
double inputfromstate = inputFromState();
double inputfromgoals = inputFromGoals();
inputfromstate = inputFromState();
inputfromgoals = inputFromGoals();
double takenawaybyprotectedgoals = takenAwayByProtectedGoals();
double spreadbw = spreadBw();
double spreadfw = spreadFw();
spreadbw = spreadBw();
spreadfw = spreadFw();
double takenaway = takenAway();

activation = inputfromstate + inputfromgoals - takenawaybyprotectedgoals + (spreadbw + spreadfw - takenaway);
Expand Down Expand Up @@ -830,10 +837,12 @@ public double inputFromState()
MODULE_softPrecon_and_ClassicPrecon.addAll(module.getListOfPreconditions());
MODULE_softPrecon_and_ClassicPrecon.addAll(module.getSoftPreconList());

if (MODULE_softPrecon_and_ClassicPrecon.contains(j))
{
sharpM = sharpM + 1;
}
for(Memory item : MODULE_softPrecon_and_ClassicPrecon) {
Copy link

Choose a reason for hiding this comment

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

Avoid deeply nested control flow statements.

if (item.getI().equals(j.getI()))
{
sharpM = sharpM + 1;
}
}
} finally
{
lock.unlock();
Expand Down Expand Up @@ -895,10 +904,12 @@ public double inputFromGoals()
{
try
{
if (module.getAddList().contains(j))
{
sharpA = sharpA + 1;
}
for(Memory addItem : module.getAddList()) {

This comment was marked as duplicate.

if (addItem.getI().equals(j.getI()))
{
sharpA = sharpA + 1;
}
}
} finally
{
lock.unlock();
Expand Down Expand Up @@ -948,10 +959,12 @@ public double takenAwayByProtectedGoals()
{
try
{
if (module.getDeleteList().contains(j))
{
sharpU = sharpU + 1;
}
for(Memory deleteItem : module.getDeleteList()) {
Copy link

Choose a reason for hiding this comment

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

Avoid deeply nested control flow statements.

if (deleteItem.getI().equals(j.getI()))
{
sharpU = sharpU + 1;
}
}
} finally
{
lock.unlock();
Expand Down Expand Up @@ -1429,22 +1442,28 @@ public void clearActionList(){
private double competencesWithPropInPrecon(Memory proposition)
{
double compWithProp = 0;
for (Behavior comp : this.getCoalition())
{
if (impendingAccess(comp))
{
try
{
if (comp.getListOfPreconditions().contains(proposition)||comp.getSoftPreconList().contains(proposition))
{
compWithProp = compWithProp + 1;
}
} finally
{
lock.unlock();
comp.lock.unlock();
}
}
for (Behavior comp : this.getCoalition()) {
if (impendingAccess(comp)) {
try {
Boolean hasFound = false;
for(Memory preconItem : comp.getListOfPreconditions()) {
if (preconItem.getI().equals(proposition.getI())) {
compWithProp = compWithProp + 1;
}
}
if (!hasFound) {
for(Memory softPreconItem : comp.getSoftPreconList()) {
if (softPreconItem.getI().equals(proposition.getI())) {
Copy link

Choose a reason for hiding this comment

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

Avoid deeply nested control flow statements.

compWithProp = compWithProp + 1;
}
}
}

} finally {
lock.unlock();
comp.lock.unlock();
}
}
}
return compWithProp;
}
Expand All @@ -1455,52 +1474,48 @@ private double competencesWithPropInPrecon(Memory proposition)
*/
private double competencesWithPropInAdd(Memory proposition)
{
double compWithProp = 0;
for (Behavior comp : this.getCoalition())
{
if (impendingAccess(comp))
{
try
{
if (comp.getAddList().contains(proposition))
{
compWithProp = compWithProp + 1;
}
} finally
{
lock.unlock();
comp.lock.unlock();
}
}
}
return compWithProp;
double compWithProp = 0;
for (Behavior comp : this.getCoalition()) {
if (impendingAccess(comp)) {
try {
for(Memory addItem : comp.getAddList()) {
if (addItem.getI().equals(proposition.getI()))
{
compWithProp = compWithProp + 1;
break;
}
}
} finally {
lock.unlock();
comp.lock.unlock();
}
}
}
return compWithProp;
}


/**
* Returns the list of competences from coalition with the given proposition in its del lists
*/
private double competencesWithPropInDel(Memory proposition)
{
double compWithProp = 0;
for (Behavior comp : this.getCoalition())
{
if (impendingAccess(comp))
{
try
{
if (comp.getDeleteList().contains(proposition))
{
compWithProp = compWithProp + 1;
}
} finally
{
lock.unlock();
comp.lock.unlock();
}
}
}
return compWithProp;
private double competencesWithPropInDel(Memory proposition) {
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

double compWithProp = 0;
for (Behavior comp : this.getCoalition()) {
if (impendingAccess(comp)) {
try {
for(Memory deleteItem : comp.getDeleteList()) {
if (deleteItem.getI().equals(proposition.getI())) {
compWithProp = compWithProp + 1;
break;
}
}
} finally {
lock.unlock();
comp.lock.unlock();
}
}
}
return compWithProp;
}

/**
Expand Down Expand Up @@ -1561,4 +1576,34 @@ public ArrayList<Memory> getSoftPreconList() {
public void setSoftPreconList(ArrayList<Memory> softPreconList) {
this.softPreconList = softPreconList;
}
/**
* @return the inputfromstate
*/
public double getInputfromstate() {
return inputfromstate;
}
/**
* @return the inputfromgoals
*/
public double getInputfromgoals() {
return inputfromgoals;
}
/**
* @return the spreadbw
*/
public double getSpreadbw() {
return spreadbw;
}
/**
* @return the spreadfw
*/
public double getSpreadfw() {
return spreadfw;
}
/**
* @return the activationWhenActive
*/
public double getActivationWhenActive(){
return activationWhenActive;
}
}
8 changes: 6 additions & 2 deletions src/main/java/br/unicamp/cst/behavior/bn/BehaviorsWTA.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ public void calculateActivation() {
// TODO Auto-generated method stub

}


/**
* @return the chosenBehavior from bn iteraction
*/
public Behavior getChosenBehavior() {
return this.chosenBehavior;
}

}

Expand Down
Loading
Loading