From e146ab4e6bd169fdbbabf00005479e799bdc66f0 Mon Sep 17 00:00:00 2001 From: Eduardo Eloy Date: Thu, 24 Nov 2022 18:00:13 +0000 Subject: [PATCH] selecttable criteria --- MODFIRE-Prototype/allSolutionPairs.csv | 0 MODFIRE-Prototype/nonPareto.csv | 0 MODFIRE-Prototype/out/production/MODFIRE-Prototype/CustomPropagator2.class | Bin 5665 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/GetInput.class | Bin 11936 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/Main5Criteria.class | Bin 17698 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainDistance.class | Bin 19509 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainLimit.class | Bin 18857 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainRegion.class | Bin 19054 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainWithSpecific.class | Bin 19570 -> 0 bytes MODFIRE-Prototype/out/production/MODFIRE-Prototype/MultiOutput.class | Bin 11220 -> 0 bytes MODFIRE-Prototype/outputPairs.csv | 193 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ MODFIRE-Prototype/src/CustomPropagator2.java | 2 +- MODFIRE-Prototype/src/GetInput.java | 2 +- MODFIRE-Prototype/src/Main5Criteria.java | 2 +- MODFIRE-Prototype/src/MainDistance.java | 2 +- MODFIRE-Prototype/src/MainLimit.java | 2 +- MODFIRE-Prototype/src/MainRegion.java | 2 +- MODFIRE-Prototype/src/MainWithSpecific.java | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------ MODFIRE-Prototype/src/MultiOutput.java | 2 +- 19 files changed, 339 insertions(+), 79 deletions(-) create mode 100644 MODFIRE-Prototype/allSolutionPairs.csv create mode 100644 MODFIRE-Prototype/nonPareto.csv create mode 100644 MODFIRE-Prototype/outputPairs.csv diff --git a/MODFIRE-Prototype/allSolutionPairs.csv b/MODFIRE-Prototype/allSolutionPairs.csv new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/MODFIRE-Prototype/allSolutionPairs.csv diff --git a/MODFIRE-Prototype/nonPareto.csv b/MODFIRE-Prototype/nonPareto.csv new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/MODFIRE-Prototype/nonPareto.csv diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/CustomPropagator2.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/CustomPropagator2.class index 4bba02a..5ce83af 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/CustomPropagator2.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/CustomPropagator2.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/GetInput.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/GetInput.class index 3495cc8..f061b92 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/GetInput.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/GetInput.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/Main5Criteria.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/Main5Criteria.class index 568a855..6cf3eeb 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/Main5Criteria.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/Main5Criteria.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainDistance.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainDistance.class index 8724495..09ef550 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainDistance.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainDistance.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainLimit.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainLimit.class index a413ef9..cdb6b7a 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainLimit.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainLimit.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainRegion.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainRegion.class index 85e5f6f..452a840 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainRegion.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainRegion.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainWithSpecific.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainWithSpecific.class index 37e9e7e..9fa28f8 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainWithSpecific.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MainWithSpecific.class differ diff --git a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MultiOutput.class b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MultiOutput.class index a1bd183..f825ae7 100644 Binary files a/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MultiOutput.class and b/MODFIRE-Prototype/out/production/MODFIRE-Prototype/MultiOutput.class differ diff --git a/MODFIRE-Prototype/outputPairs.csv b/MODFIRE-Prototype/outputPairs.csv new file mode 100644 index 0000000..bdd256f --- /dev/null +++ b/MODFIRE-Prototype/outputPairs.csv @@ -0,0 +1,193 @@ +3,20 +4,500 +5,500 +7,1 +19,2 +20,1 +21,1 +22,1 +23,1 +24,1 +29,1 +34,1 +39,1 +40,1 +41,3 +46,1 +59,500 +63,500 +64,1 +66,500 +90,500 +91,20 +92,3 +93,500 +95,1 +97,1 +98,2 +99,2 +100,2 +101,501 +102,500 +103,501 +104,500 +105,3 +106,3 +108,2 +109,500 +110,1 +135,308 +136,2 +138,1 +144,1 +153,304 +163,500 +164,1 +172,500 +173,500 +174,1 +177,1 +178,3 +180,1 +181,3 +184,1 +187,1 +194,500 +195,1 +196,2 +210,500 +218,1 +219,500 +225,500 +226,3 +227,3 +229,2 +230,1 +231,3 +235,1 +236,3 +237,3 +246,2 +247,1 +248,3 +250,1 +251,2 +255,3 +256,19 +257,19 +258,2 +259,500 +260,1 +266,1 +267,1 +268,1 +269,3 +270,501 +271,312 +272,1 +274,500 +275,1 +276,1 +277,500 +278,2 +297,1 +307,316 +348,1 +363,3 +364,1 +368,1 +369,3 +370,1 +371,500 +372,2 +373,3 +374,500 +375,3 +376,1 +377,1 +378,1 +379,500 +380,1 +381,1 +384,500 +385,500 +386,1 +387,1 +391,3 +408,1 +409,1 +410,3 +414,1 +427,500 +428,500 +429,500 +433,1 +458,500 +459,1 +460,3 +461,3 +464,3 +465,2 +470,502 +474,802 +483,500 +484,1 +501,2 +502,2 +503,1 +504,1 +505,2 +512,500 +533,500 +555,19 +556,3 +557,2 +558,2 +559,3 +560,1 +586,1 +587,1 +588,3 +589,15 +590,500 +591,19 +592,3 +605,3 +606,2 +611,500 +612,3 +614,1 +615,1 +616,1 +618,2 +619,2 +642,3 +655,800 +675,1 +678,3 +679,1 +682,2 +712,29 +713,2 +730,34 +731,1 +736,500 +737,308 +742,2 +743,2 +746,801 +748,801 +749,500 +755,1 +756,1 +757,1 +762,3 +763,1 +764,1 +767,1 +773,500 +774,3600 +775,304 +776,801 +777,801 +782,1 diff --git a/MODFIRE-Prototype/src/CustomPropagator2.java b/MODFIRE-Prototype/src/CustomPropagator2.java index d67f432..902ad8c 100644 --- a/MODFIRE-Prototype/src/CustomPropagator2.java +++ b/MODFIRE-Prototype/src/CustomPropagator2.java @@ -16,7 +16,7 @@ public class CustomPropagator2 extends org.chocosolver.solver.constraints.Propag - public CustomPropagator2(int ugIndex, UG[] nodes, IntVar[] ugs, int sum, IntVar[] woodYield) { + public CustomPropagator2(int ugIndex, UG[] nodes, IntVar[] ugs, int sum ) { super(ugs, PropagatorPriority.LINEAR, false); this.ugIndex = ugIndex; this.nodes = nodes; diff --git a/MODFIRE-Prototype/src/GetInput.java b/MODFIRE-Prototype/src/GetInput.java index 91a05f9..7d76fc7 100644 --- a/MODFIRE-Prototype/src/GetInput.java +++ b/MODFIRE-Prototype/src/GetInput.java @@ -170,7 +170,7 @@ public class GetInput { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } diff --git a/MODFIRE-Prototype/src/Main5Criteria.java b/MODFIRE-Prototype/src/Main5Criteria.java index 44ea786..218ddfa 100644 --- a/MODFIRE-Prototype/src/Main5Criteria.java +++ b/MODFIRE-Prototype/src/Main5Criteria.java @@ -311,7 +311,7 @@ public class Main5Criteria { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } diff --git a/MODFIRE-Prototype/src/MainDistance.java b/MODFIRE-Prototype/src/MainDistance.java index d45b118..f2121a1 100644 --- a/MODFIRE-Prototype/src/MainDistance.java +++ b/MODFIRE-Prototype/src/MainDistance.java @@ -295,7 +295,7 @@ public class MainDistance { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } diff --git a/MODFIRE-Prototype/src/MainLimit.java b/MODFIRE-Prototype/src/MainLimit.java index 2b5de03..4852807 100644 --- a/MODFIRE-Prototype/src/MainLimit.java +++ b/MODFIRE-Prototype/src/MainLimit.java @@ -278,7 +278,7 @@ public class MainLimit { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } diff --git a/MODFIRE-Prototype/src/MainRegion.java b/MODFIRE-Prototype/src/MainRegion.java index 696482b..2b35071 100644 --- a/MODFIRE-Prototype/src/MainRegion.java +++ b/MODFIRE-Prototype/src/MainRegion.java @@ -281,7 +281,7 @@ public class MainRegion { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } diff --git a/MODFIRE-Prototype/src/MainWithSpecific.java b/MODFIRE-Prototype/src/MainWithSpecific.java index f948b4f..813427e 100644 --- a/MODFIRE-Prototype/src/MainWithSpecific.java +++ b/MODFIRE-Prototype/src/MainWithSpecific.java @@ -228,21 +228,8 @@ public class MainWithSpecific { String fileDirectory = args[1]; ArrayList islandUGs = new ArrayList<>(); - /*File island = new File("i_east"); - Scanner islandReader = new Scanner(island); - while (islandReader.hasNextLine()) { - islandUGs.add(Integer.parseInt(islandReader.nextLine())); - - } - - island = new File("i_eastop"); - islandReader = new Scanner(island); - while (islandReader.hasNextLine()) { - islandUGs.add(Integer.parseInt(islandReader.nextLine())); - }*/ - - File island = new File("subregions/ip_continent"); + File island = new File("subregions/i_top"); Scanner islandReader = new Scanner(island); while (islandReader.hasNextLine()) { islandUGs.add(Integer.parseInt(islandReader.nextLine())); @@ -265,6 +252,31 @@ public class MainWithSpecific { default: R = 0;} + + + /*Set Flags + 0-woodYield + 1-Soil Loss + 2-Perc_r + 3-Biodiversity + 4-Cashflow + 5-Carbon Stock + 6-NPV + 7-Perc_rait + 8-R + 9-Rait + 10-Sbiom + */ + String[] varNames = new String[]{"WoodYield","SoilLoss","Perc_r","Biodiversity","Cashflow","CarbonStock","NPV","Perc_rait","R","Rait","Sbiom"}; + ArrayList flags = new ArrayList(); + for(int i = 0; i < 11; i++) { + flags.add(false); + } + for(int i = 4; i < args.length; i++) { + flags.set(Integer.parseInt(args[i]), true); + } + + Model m = new Model("Forest Management"); BufferedReader reader = new BufferedReader(new FileReader(fileDirectory + "/ugs_init.txt")); @@ -283,6 +295,7 @@ public class MainWithSpecific { IntVar[] ugs = new IntVar[nUgs]; // same for the constraint variable array + IntVar[] woodYield = new IntVar[nUgs]; IntVar[] soillossTotal = new IntVar[nUgs]; @@ -298,7 +311,6 @@ public class MainWithSpecific { IntVar[] rait_total = new IntVar[nUgs]; IntVar[] sbiom_total = new IntVar[nUgs]; - giveDomains(m, ugs, fileDirectory, woodYield, soillossTotal, perc_r_Total, biodiversity_total, cashflow_total, cstock_total, npv_total, perc_rait_total, r_total, rait_total, sbiom_total, nodes, R_option); // reads the ugs_init file and initializes each variable with its possible prescription values as domain @@ -310,7 +322,7 @@ public class MainWithSpecific { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } @@ -401,23 +413,41 @@ public class MainWithSpecific { IntVar raitSum = m.intVar("RaitR"+R,0, 99999999); IntVar sbiomSum = m.intVar("SbiomR"+R,0, 99999999); - - m.sum(woodYield,"=", woodSum).post(); - m.sum(soillossTotal,"=", soilSum).post(); - m.sum(perc_r_Total,"=", percRSum).post(); - - m.sum(biodiversity_total, "=", bioSum).post(); - m.sum(cashflow_total, "=", cashSum).post(); - //m.sum(cstock_total, "=", cstockSum).post(); - //m.sum(npv_total, "=", npvSum).post(); - //m.sum(perc_rait_total, "=", percRaitSum).post(); - //m.sum(r_total, "=", rSum).post(); - //m.sum(rait_total, "=", raitSum).post(); - // m.sum(sbiom_total, "=", sbiomSum).post(); + System.out.println(flags.get(0)); + System.out.println(flags.get(1)); + System.out.println(flags.get(2)); + + if(flags.get(0)) + m.sum(woodYield,"=", woodSum).post(); + if(flags.get(1)) + m.sum(soillossTotal,"=", soilSum).post(); + if(flags.get(2)) + m.sum(perc_r_Total,"=", percRSum).post(); + if(flags.get(3)) + m.sum(biodiversity_total, "=", bioSum).post(); + if(flags.get(4)) + m.sum(cashflow_total, "=", cashSum).post(); + if(flags.get(5)) + m.sum(cstock_total, "=", cstockSum).post(); + if(flags.get(6)) + m.sum(npv_total, "=", npvSum).post(); + if(flags.get(7)) + m.sum(perc_rait_total, "=", percRaitSum).post(); + if(flags.get(8)) + m.sum(r_total, "=", rSum).post(); + if(flags.get(9)) + m.sum(rait_total, "=", raitSum).post(); + if(flags.get(10)) + m.sum(sbiom_total, "=", sbiomSum).post(); + + + IntVar[] toOptimize = new IntVar[10]; + IntVar[] allSums = new IntVar[]{woodSum, soilSum, percRSum, bioSum,cashSum,cstockSum,npvSum,percRaitSum,rSum,raitSum,sbiomSum}; + IntVar[][] allTotals = new IntVar[][]{woodYield, soillossTotal,perc_r_Total,biodiversity_total,cashflow_total,cstock_total,npv_total,perc_rait_total,r_total,rait_total,sbiom_total}; // Single Criterion Optimization if(criterion.equalsIgnoreCase("single")) { - m.setObjective(Model.MAXIMIZE, woodSum); + //m.setObjective(Model.MAXIMIZE, woodSum); //m.setObjective(Model.MAXIMIZE, soilSum); //m.setObjective(Model.MAXIMIZE, percRSum); @@ -428,7 +458,14 @@ public class MainWithSpecific { FileWriter outputPairs = new FileWriter("outputPairs.csv"); for (int i = 0; i < ugs.length; i++) { if (nodes[i].valid) { - System.out.println(ugs[i] + ", wy:" + woodYield[i] + ", sl:" + soillossTotal[i] + ", R" + R + ":" + perc_r_Total[i]); + System.out.print(ugs[i] + ", "); + + for (int j = 0; j < flags.size(); j++) { + if (flags.get(j)) + System.out.print(varNames[j]+":"+ allTotals[j][i] +","); + } + System.out.println("end"); + outputPairs.write(nodes[i].externalId + "," + ugs[i].getValue() + "\n"); } } @@ -442,17 +479,29 @@ public class MainWithSpecific { else { //Multi Criterion with Pareto + int index = 0; + for(int i = 1; i paretoFront = po.getParetoFront(); System.out.println("The pareto front has " + paretoFront.size() + " solutions : "); - FileWriter outputPairs = new FileWriter("outputPairsTopIslandWSR0.csv"); + FileWriter outputPairs = new FileWriter("outputPairsSpecif.csv"); - FileWriter paretoWS = new FileWriter("paretoWS.csv"); - FileWriter paretoWR = new FileWriter("paretoWR.csv"); - FileWriter paretoSR = new FileWriter("paretoSR.csv"); - FileWriter paretoWSR = new FileWriter("paretoWSR.csv"); + FileWriter pareto = new FileWriter("pareto.csv"); int l2 = 0; for (Solution so : paretoFront) { - System.out.println("Wood = " + so.getIntVal(woodSum) + ", Soil = " + so.getIntVal(soilSum)+ - ", Perc_R"+R+":"+so.getIntVal(percRSum)); - outputPairs.write("Pareto Solution: " + l2 + ", Wood: "+so.getIntVal(woodSum)+", Soil:"+so.getIntVal(soilSum)+ - ", Perc_R"+R+":"+so.getIntVal(percRSum)+"\n"); + + for (int i = 0; i < flags.size(); i++) { + if (flags.get(i)) + System.out.print(varNames[i]+"="+so.getIntVal(allSums[i])+","); + } + System.out.println("end"); + + outputPairs.write("Pareto Solution: " + l2+","); + for (int i = 0; i < flags.size(); i++) { + if (flags.get(i)) + outputPairs.write(varNames[i]+":"+so.getIntVal(allSums[i])+","); + } + + outputPairs.write("end+\n"); + for (int i = 0; i < ugs.length; i++) { if (nodes[i].valid) { - System.out.println(i+"_"+so.getIntVal(ugs[i]) + ", wy:" + so.getIntVal(woodYield[i]) + ", sl:" + - so.getIntVal(soillossTotal[i]) + ", R" + R + ":" + so.getIntVal(perc_r_Total[i])); - outputPairs.write(nodes[i].externalId + "," +so.getIntVal(ugs[i]) + "\n"); - } - } + System.out.print(i+"_"+so.getIntVal(ugs[i])+", "); - //PARETO POINTS - paretoWS.write(so.getIntVal(woodSum)+","+so.getIntVal(soilSum)+"\n"); - paretoWR.write(so.getIntVal(woodSum)+","+so.getIntVal(percRSum)+"\n"); - paretoSR.write(so.getIntVal(soilSum)+","+so.getIntVal(percRSum)+"\n"); - paretoWSR.write(so.getIntVal(woodSum)+","+so.getIntVal(soilSum)+","+so.getIntVal(percRSum)+"\n"); + for (int j = 0; j < flags.size(); j++) { + if (flags.get(j)) + System.out.print(varNames[j]+":"+so.getIntVal(allTotals[j][i])+","); + } + System.out.println("end"); + outputPairs.write(nodes[i].externalId + "," +so.getIntVal(ugs[i]) + "\n"); + } + } + pareto.write(so.getIntVal(woodSum)+","+so.getIntVal(soilSum)+","+so.getIntVal(percRSum)+"\n"); l2++; } outputPairs.close(); - paretoWS.close(); - paretoWR.close(); - paretoSR.close(); - paretoWSR.close(); + + pareto.close(); System.out.println(l + " solutions"); } } diff --git a/MODFIRE-Prototype/src/MultiOutput.java b/MODFIRE-Prototype/src/MultiOutput.java index 0503b4f..7720f8b 100644 --- a/MODFIRE-Prototype/src/MultiOutput.java +++ b/MODFIRE-Prototype/src/MultiOutput.java @@ -163,7 +163,7 @@ public class MultiOutput { //the propagator takes as parameters the index of the UG we are starting out from //the nodes with all the info, the constraint variable array and the area limit if(nodes[ugIndex].valid) { - new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit, woodYield)).post(); + new Constraint("Area Limit Constraint", new CustomPropagator2(ugIndex, nodes, ugs, areaLimit)).post(); } } -- libgit2 0.21.2