import org.chocosolver.solver.Model; import org.chocosolver.solver.Solution; import org.chocosolver.solver.Solver; import org.chocosolver.solver.constraints.Constraint; import org.chocosolver.solver.objective.ParetoOptimizer; import org.chocosolver.solver.variables.IntVar; import java.io.*; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Getdists { public static void giveDomains (Model model, IntVar[] ugs, String dir, IntVar[] woodYield, IntVar[] soillossTotal, IntVar[] perc_r_Total, UG[] nodes, int R_option){ int index = 0; try { File allUg = new File(dir + "/ugs_init.txt"); Scanner readerUg = new Scanner(allUg); File myObjWood = new File(dir + "/wood_total_init.txt"); Scanner myReaderWood = new Scanner(myObjWood); File myObjSoil = new File(dir + "/soilloss_total_init.txt"); Scanner myReaderSoil = new Scanner(myObjSoil); String percR_dir; int R; switch(R_option) { case 1: percR_dir = "/perc_r5_total_init.txt"; R = 5; break; case 2: percR_dir = "/perc_r10_total_init.txt"; R = 10; break; default: percR_dir = "/perc_r0_total_init.txt"; R = 0; } File myObjPerc_r = new File(dir + percR_dir); Scanner myReaderPerc_r = new Scanner(myObjPerc_r); while (readerUg.hasNextLine()) { String dataUg = readerUg.nextLine(); String dataWood = myReaderWood.nextLine(); String dataSoil = myReaderSoil.nextLine(); String dataPerc_r = myReaderPerc_r.nextLine(); if(nodes[index].valid) { String[] str_split = dataUg.split(",", 0); String[] str_split_wood = dataWood.split(",", 0); String[] str_split_soil = dataSoil.split(",", 0); String[] str_split_percr = dataPerc_r.split(",", 0); int size = str_split.length; int[] toInsert = new int[size]; int[] toInsertWood = new int[size]; int[] toInsertSoil = new int[size]; int[] toInsertPercR = new int[size]; for (int i = 0; i < size; i++) { toInsert[i] = Integer.parseInt(str_split[i]); toInsertWood[i] = (int) Float.parseFloat(str_split_wood[i]); toInsertSoil[i] = (int) Float.parseFloat(str_split_soil[i]); toInsertPercR[i] = (int) Float.parseFloat(str_split_percr[i]); } ugs[index] = model.intVar("UG_" + (index), toInsert); woodYield[index] = model.intVar("Wood_Yield_" + (index), toInsertWood); soillossTotal[index] = model.intVar("Soilloss_" + (index), toInsertSoil); perc_r_Total[index] = model.intVar("RiskPercentileR"+R+":" + (index), toInsertPercR); } else { ugs[index] = model.intVar("UG_"+(index), 0); woodYield[index] = model.intVar("Wood_Yield_"+(index), 0); soillossTotal[index] = model.intVar("Soilloss_" + (index), 0); perc_r_Total[index] = model.intVar("RiskPercentileR"+R+":" + (index), 0); } index++; } readerUg.close(); myReaderWood.close(); myReaderSoil.close(); myReaderPerc_r.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(); } } public static void main(String[] args) throws IOException { int startingMU = 1107; int distance = 1000; BufferedReader reader = new BufferedReader(new FileReader( "res/ugs_init.txt")); int nUgs = 0; while (reader.readLine() != null) nUgs++; reader.close(); ArrayList islandUGs = new ArrayList<>(); File island = new File("ip_east"); Scanner islandReader = new Scanner(island); while (islandReader.hasNextLine()) { islandUGs.add(Integer.parseInt(islandReader.nextLine())); } island = new File("ip_west"); islandReader = new Scanner(island); while (islandReader.hasNextLine()) { islandUGs.add(Integer.parseInt(islandReader.nextLine())); } islandReader.close(); UG[] nodes = new UG[nUgs]; UG.fillArray(nodes, "res", 20000); int X,Y; int startX = (int) nodes[startingMU].medx; int startY = (int) nodes[startingMU].medy; int o = 0; for(int i = 0; i distance || nodes[i].region.compareToIgnoreCase("penafiel")==0||nodes[i].region.compareToIgnoreCase("paredes")==0) { nodes[i].valid = false; } else{ System.out.println(nodes[i].externalId); o++; } } //for(int i = 0; i < nodes.length; i++){ // if(!islandUGs.contains(nodes[i].externalId) & nodes[i].region.equalsIgnoreCase("Paiva")) // System.out.println(nodes[i].externalId); //} //System.out.println(o); } }