-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
{ | ||
|
@@ -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(); | ||
|
@@ -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); | ||
|
@@ -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) { | ||
if (item.getI().equals(j.getI())) | ||
{ | ||
sharpM = sharpM + 1; | ||
} | ||
} | ||
} finally | ||
{ | ||
lock.unlock(); | ||
|
@@ -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.
Sorry, something went wrong. |
||
if (addItem.getI().equals(j.getI())) | ||
{ | ||
sharpA = sharpA + 1; | ||
} | ||
} | ||
} finally | ||
{ | ||
lock.unlock(); | ||
|
@@ -948,10 +959,12 @@ public double takenAwayByProtectedGoals() | |
{ | ||
try | ||
{ | ||
if (module.getDeleteList().contains(j)) | ||
{ | ||
sharpU = sharpU + 1; | ||
} | ||
for(Memory deleteItem : module.getDeleteList()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
@@ -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())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
/** | ||
|
@@ -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; | ||
} | ||
} |
There was a problem hiding this comment.
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.