Skip to content

Commit

Permalink
change property value ("1" for "true"), add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-schmid committed Aug 30, 2022
1 parent c633f7c commit a08ed4b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions control.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ precalc_MPdata_folder = data/data-precalculated-test/MPdata
uncertainty = 1
year = 2
project_folder = projdir
noOptOut = 0
debug = 0
8 changes: 5 additions & 3 deletions src/main/java/farmind/agent/Farm.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public List<String> decideActivitySet(List<Farm> allFarms, Properties cmd) {
FuzzyLogicCalculator fuzzyLogicCalc = new FuzzyLogicCalculator(this, allFarms); // calculator for the activity selection

// modified simulation using only satisfaction
if ( Integer.parseInt(cmd.getProperty("uncertainty")) == 0) {
if (cmd.getProperty("uncertainty").equals("0")) {
if (this.Satisfaction >= this.getP_aspiration_coef() ) {
this.strategy = 4; //REPETITION
for (int i = 0; i < this.getCurrentActivity().size(); i++) {
Expand All @@ -173,8 +173,10 @@ public List<String> decideActivitySet(List<Farm> allFarms, Properties cmd) {

// Full simulation using dissimilarity and satisfaction
else {
if ( (this.Activity_Dissimilarity >= this.p_activity_tolerance_coef) || (this.Income_Dissimilarity >= this.p_income_tolerance_coef) ) {
if (cmd.getProperty("noOptOut") == "true" || this.Satisfaction >= this.getP_aspiration_coef()) {
if (this.Activity_Dissimilarity >= this.p_activity_tolerance_coef
|| this.Income_Dissimilarity >= this.p_income_tolerance_coef) {
if (cmd.getProperty("noOptOut").equals("1")
|| this.Satisfaction >= this.getP_aspiration_coef()) {
this.strategy = 2; //IMITATION
ActivitySet = fuzzyLogicCalc.getImitationActivities();
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/farmind/testing/FarmTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ public void testOptOutDecision() {
assertEquals(strat, 1);
}

@Test
public void testNoOptOutDecision() {
Farm farm = allFarms.get(0);

farm.setSatisfaction(-1);
farm.setActivity_Dissimilarity(10);
farm.setIncome_Dissimilarity(0);

cmd.setProperty("noOptOut", "1");

farm.decideActivitySet(allFarms,cmd);
int strat = farm.getStrategy();
assertEquals(strat, 2);
}

@Test
public void testRepetionDecisionNoUncertainty() throws FileNotFoundException, IOException {
Farm farm = allFarms.get(0);
Expand Down
3 changes: 2 additions & 1 deletion test_data/control.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ uncertainty = 1
year = 5
start_year_simulation = 2019
project_folder = projdir
debug = 1
noOptOut = 0
debug = 1

0 comments on commit a08ed4b

Please sign in to comment.