import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class UG { int internalId; int externalId; float area; int[] adj; String region; int[] presc; int[][] years; float[][] woodByPrescYear; float[][] soillossByPrescYear; String[][] thin_or_harv; int[] wood_total; int[] perc_r0_total; int[] perc_r5_total; int[] perc_r10_total; int[] soilloss_total; float medx; float medy; int time; boolean valid; boolean treated; static public int[] returnInsertable(Scanner myReader){ String data = myReader.nextLine(); String[] str_split = data.split(",", 0); int size = str_split.length; int[] toInsert = new int [size]; for(int i=0; i minBorder){ toInsert[currentIndex] = Integer.parseInt(str_splitA[i]); currentIndex++; } } return toInsert; } static public int[] adjacencyReader(Scanner adjacencies, Scanner borders){ String dataAdj = adjacencies.nextLine(); String[] str_splitA = dataAdj.split(",", 0); String dataBorders = borders.nextLine(); String[] str_splitB = dataBorders.split(",", 0); int size = str_splitA.length; int[] toInsert = new int [size]; toInsert[0] = -1; int currentIndex = 0; for(int i=0; i= 10){ toInsert[currentIndex] = Integer.parseInt(str_splitA[i]); currentIndex++; } } return toInsert; } static public int[] returnPeriods(String data){ String[] str_split = data.split(",", 0); int size = str_split.length; int[] toInsert = new int [size]; for(int i=0; i ugLimit){ toInsert.valid = false; } array[index] = toInsert; index++; } readerAdj.close(); readerPresc.close(); readerExt.close(); readerReg.close(); readerBorders.close(); readerArea.close(); readerPerc_r0.close(); readerPerc_r5.close(); readerPerc_r10.close(); readerSoillossTotal.close(); readerThinHarv.close(); readerWoodPresc.close(); readerWoodTotal.close(); readerYears.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(); } } static public void fillArrayRegions(UG[] array, String dir, String region, int option) { int index = 0; try { // idea: pass a directory, which should contain files called // graph_init, ugs_init, ... File adj_init = new File(dir + "/adj_init.txt"); Scanner readerAdj = new Scanner(adj_init); File borders_init = new File(dir + "/border_init.txt"); Scanner readerBorders = new Scanner(borders_init); File ext_init = new File(dir + "/external_init.txt"); Scanner readerExt = new Scanner(ext_init); File reg_init = new File(dir + "/region_init.txt"); Scanner readerReg = new Scanner(reg_init); File ugs_init = new File(dir + "/ugs_init.txt"); Scanner readerPresc = new Scanner(ugs_init); File years_init = new File(dir + "/years_init.txt"); Scanner readerYears = new Scanner(years_init); File area_init = new File(dir + "/area_init.txt"); Scanner readerArea = new Scanner(area_init); File wood_total_init = new File(dir + "/wood_total_init.txt"); Scanner readerWoodTotal = new Scanner(wood_total_init); File soilloss_init = new File(dir + "/soilloss_total_init.txt"); Scanner readerSoillossTotal = new Scanner(soilloss_init); File perc_r0_init = new File(dir + "/perc_r0_total_init.txt"); Scanner readerPerc_r0 = new Scanner(perc_r0_init); File perc_r5_init = new File(dir + "/perc_r5_total_init.txt"); Scanner readerPerc_r5 = new Scanner(perc_r5_init); File perc_r10_init = new File(dir + "/perc_r10_total_init.txt"); Scanner readerPerc_r10 = new Scanner(perc_r10_init); File wood_presc_init = new File(dir + "/wood_presc_init.txt"); Scanner readerWoodPresc = new Scanner(wood_presc_init); File thin_harv_init = new File(dir + "/thin_harv_init.txt"); Scanner readerThinHarv = new Scanner(thin_harv_init); File x_init = new File(dir + "/x_init.txt"); Scanner readerX = new Scanner(x_init); File y_init = new File(dir + "/y_init.txt"); Scanner readerY = new Scanner(y_init); while (readerAdj.hasNextLine()) { UG toInsert = new UG(); toInsert.valid = true; toInsert.treated = false; toInsert.internalId = index; toInsert.adj = adjacencyReader(readerAdj, readerBorders, 50); toInsert.externalId = Integer.parseInt(readerExt.nextLine()); toInsert.area = Float.parseFloat(readerArea.nextLine()); toInsert.medx = Float.parseFloat(readerX.nextLine()); toInsert.medy = Float.parseFloat(readerY.nextLine()); toInsert.region = readerReg.nextLine(); toInsert.presc = returnInsertable(readerPresc); String data = readerYears.nextLine(); String[] removeVSlash = data.split("\\|", 0); String[] str_split = removeVSlash[1].split("/", 0); int size = str_split.length; toInsert.years = new int[size][]; for(int i = 0; i < size; i++) { toInsert.years[i] = returnPeriods(str_split[i]); } toInsert.soilloss_total = returnInsertable2(readerSoillossTotal); toInsert.perc_r0_total = returnInsertable2(readerPerc_r0); toInsert.perc_r5_total = returnInsertable2(readerPerc_r5); toInsert.perc_r10_total = returnInsertable2(readerPerc_r10); toInsert.wood_total = returnInsertable2(readerWoodTotal); data = readerWoodPresc.nextLine(); String data2 = readerThinHarv.nextLine(); str_split = data.split("/", 0); String[] str_split2 = data2.split("/", 0); size = str_split.length; int size2 = str_split2.length; toInsert.woodByPrescYear = new float[size][]; toInsert.thin_or_harv = new String[size2][]; for(int i = 0; i < size; i++) { toInsert.woodByPrescYear[i] = returnByYear(str_split[i]); toInsert.thin_or_harv[i] = returnByYearString(str_split2[i]); } if(option==0){ if(!region.equalsIgnoreCase(toInsert.region)){ //System.out.println(index); toInsert.valid = false; } } else { if (region.equalsIgnoreCase(toInsert.region)) { toInsert.valid = false; //System.out.println(index); } } if(toInsert.adj[0] == -1) toInsert.valid = false; array[index] = toInsert; index++; } readerAdj.close(); readerPresc.close(); readerExt.close(); readerReg.close(); readerBorders.close(); readerArea.close(); readerPerc_r0.close(); readerPerc_r5.close(); readerPerc_r10.close(); readerSoillossTotal.close(); readerThinHarv.close(); readerWoodPresc.close(); readerWoodTotal.close(); readerYears.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(); } } static public void fillArraySpecific(UG[] array, String dir, ArrayList list) { int index = 0; try { // idea: pass a directory, which should contain files called // graph_init, ugs_init, ... File adj_init = new File(dir + "/adj_init.txt"); Scanner readerAdj = new Scanner(adj_init); File borders_init = new File(dir + "/border_init.txt"); Scanner readerBorders = new Scanner(borders_init); File ext_init = new File(dir + "/external_init.txt"); Scanner readerExt = new Scanner(ext_init); File reg_init = new File(dir + "/region_init.txt"); Scanner readerReg = new Scanner(reg_init); File ugs_init = new File(dir + "/ugs_init.txt"); Scanner readerPresc = new Scanner(ugs_init); File years_init = new File(dir + "/years_init.txt"); Scanner readerYears = new Scanner(years_init); File area_init = new File(dir + "/area_init.txt"); Scanner readerArea = new Scanner(area_init); File wood_total_init = new File(dir + "/wood_total_init.txt"); Scanner readerWoodTotal = new Scanner(wood_total_init); File soilloss_init = new File(dir + "/soilloss_total_init.txt"); Scanner readerSoillossTotal = new Scanner(soilloss_init); File perc_r0_init = new File(dir + "/perc_r0_total_init.txt"); Scanner readerPerc_r0 = new Scanner(perc_r0_init); File perc_r5_init = new File(dir + "/perc_r5_total_init.txt"); Scanner readerPerc_r5 = new Scanner(perc_r5_init); File perc_r10_init = new File(dir + "/perc_r10_total_init.txt"); Scanner readerPerc_r10 = new Scanner(perc_r10_init); File wood_presc_init = new File(dir + "/wood_presc_init.txt"); Scanner readerWoodPresc = new Scanner(wood_presc_init); File thin_harv_init = new File(dir + "/thin_harv_init.txt"); Scanner readerThinHarv = new Scanner(thin_harv_init); File x_init = new File(dir + "/x_init.txt"); Scanner readerX = new Scanner(x_init); File y_init = new File(dir + "/y_init.txt"); Scanner readerY = new Scanner(y_init); while (readerAdj.hasNextLine()) { UG toInsert = new UG(); toInsert.valid = true; toInsert.treated = false; toInsert.internalId = index; toInsert.adj = adjacencyReader(readerAdj, readerBorders, 50); toInsert.externalId = Integer.parseInt(readerExt.nextLine()); toInsert.area = Float.parseFloat(readerArea.nextLine()); toInsert.medx = Float.parseFloat(readerX.nextLine()); toInsert.medy = Float.parseFloat(readerY.nextLine()); toInsert.region = readerReg.nextLine(); toInsert.presc = returnInsertable(readerPresc); String data = readerYears.nextLine(); String[] removeVSlash = data.split("\\|", 0); String[] str_split = removeVSlash[1].split("/", 0); int size = str_split.length; toInsert.years = new int[size][]; for(int i = 0; i < size; i++) { toInsert.years[i] = returnPeriods(str_split[i]); } toInsert.soilloss_total = returnInsertable2(readerSoillossTotal); toInsert.perc_r0_total = returnInsertable2(readerPerc_r0); toInsert.perc_r5_total = returnInsertable2(readerPerc_r5); toInsert.perc_r10_total = returnInsertable2(readerPerc_r10); toInsert.wood_total = returnInsertable2(readerWoodTotal); data = readerWoodPresc.nextLine(); String data2 = readerThinHarv.nextLine(); str_split = data.split("/", 0); String[] str_split2 = data2.split("/", 0); size = str_split.length; int size2 = str_split2.length; toInsert.woodByPrescYear = new float[size][]; toInsert.thin_or_harv = new String[size2][]; for(int i = 0; i < size; i++) { toInsert.woodByPrescYear[i] = returnByYear(str_split[i]); toInsert.thin_or_harv[i] = returnByYearString(str_split2[i]); } if(!list.contains(toInsert.externalId)){ toInsert.valid = false; } array[index] = toInsert; index++; } readerAdj.close(); readerPresc.close(); readerExt.close(); readerReg.close(); readerBorders.close(); readerArea.close(); readerPerc_r0.close(); readerPerc_r5.close(); readerPerc_r10.close(); readerSoillossTotal.close(); readerThinHarv.close(); readerWoodPresc.close(); readerWoodTotal.close(); readerYears.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTrace(); } } }