Skip to content

Commit

Permalink
fixing bugs about law enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu committed Aug 31, 2020
1 parent d496589 commit 1b3deff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Expand Up @@ -156,7 +156,7 @@ protected Object privateExecuteIn(final IScope scope) throws GamaRuntimeExceptio
// Les sanctions et rewards seront ici appliquées dans le cadre de l'agent controlé car directe
final MentalState tempObligation = new MentalState("obligation", (Predicate) obligation.value(scope));
if (SimpleBdiArchitecture.hasObligation(scope, tempObligation)) {
// si ma norme en cours répond à l'iobligation , reward, sinon punition.
// si ma norme en cours répond à l'obligation , reward, sinon punition.
Norm tempNorm = null;// new Norm ((NormStatement)scope.getAgent().getAttribute("CURRENT_NORM"));
for (final Norm testNorm : SimpleBdiArchitecture.getNorms(scope)) {
if (testNorm.getObligation(scope) != null
Expand Down Expand Up @@ -215,6 +215,8 @@ protected Object privateExecuteIn(final IScope scope) throws GamaRuntimeExceptio
if (law != null) {
// on recherche la norme avec le même nom chez l'autre et on regarde si elle est violée
LawStatement lawToTest = null;
Double obedienceValue = (Double) scope.getAgent().getAttribute("obedience");
Boolean isViolated = true;
// Améliorable en temps de calcul
for (final LawStatement tempLaw : SimpleBdiArchitecture.getLaws(scope)) {
if (tempLaw.getName().equals(law.value(scopeMySelf))) {
Expand All @@ -232,6 +234,10 @@ protected Object privateExecuteIn(final IScope scope) throws GamaRuntimeExceptio
|| lawToTest.getObligationExpression().value(scope) == null
|| SimpleBdiArchitecture.hasObligation(scope, new MentalState("Obligation",
(Predicate) lawToTest.getObligationExpression().value(scope)))) {
if(lawToTest.getThreshold() == null
|| lawToTest.getThreshold().value(scope) == null
|| obedienceValue>= (Double) lawToTest.getThreshold().value(scope)) {
isViolated = false;
if (reward != null) {
Sanction rewardToExecute = null;
// Améliorable en temps de calcul
Expand All @@ -244,7 +250,10 @@ protected Object privateExecuteIn(final IScope scope) throws GamaRuntimeExceptio
retour = rewardToExecute.getSanctionStatement().executeOn(scopeMySelf);
}
}
} else {
}
}
}
} if(isViolated) {
if (sanction != null) {
Sanction sanctionToExecute = null;
// Améliorable en temps de calcul
Expand All @@ -259,10 +268,9 @@ protected Object privateExecuteIn(final IScope scope) throws GamaRuntimeExceptio
}
}
}
}
}
}
}

GAMA.releaseScope(scopeMySelf);
}
return retour;
Expand Down
Expand Up @@ -138,6 +138,10 @@ public IExpression getParallel() {
return parallel;
}

public IExpression getThreshold() {
return threshold;
}

public LawStatement(IDescription desc) {
super(desc);
when = getFacet(IKeyword.WHEN);
Expand Down

0 comments on commit 1b3deff

Please sign in to comment.