From 9ea84311ccfc3dca0eab602509d1c74693c1fb3b Mon Sep 17 00:00:00 2001 From: shivam-a Date: Wed, 10 May 2023 18:17:32 +0530 Subject: [PATCH] new changes 8.05.2023 --- .../playground/shivam/signals/RunSignals.java | 41 ++++++++++--------- .../shivam/signals/SignalUtils.java | 3 +- .../shivam/signals/config/CreateConfig.java | 12 +++--- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/main/java/playground/shivam/signals/RunSignals.java b/src/main/java/playground/shivam/signals/RunSignals.java index 19dff28e..0aa206cc 100644 --- a/src/main/java/playground/shivam/signals/RunSignals.java +++ b/src/main/java/playground/shivam/signals/RunSignals.java @@ -66,7 +66,7 @@ public static void main(String[] args) throws IOException { adaptiveTimeSignal(false); break; case 3: - compareMixedTrafficSignals(false); + compareTrafficSignals(false); break; case 4: fixedTimeSignal(true); @@ -75,7 +75,7 @@ public static void main(String[] args) throws IOException { adaptiveTimeSignal(true); break; case 6: - compareMixedTrafficSignals(true); + compareTrafficSignals(true); default: System.out.println("You have exited"); } @@ -83,7 +83,7 @@ public static void main(String[] args) throws IOException { } static void fixedTimeSignal(boolean homogenous) throws IOException { - outputDirectory = "output/fixedTimeSignal/"; + outputDirectory = "output/fixedTimeSignal_" + RUN + "/" ; signalController = DefaultPlanbasedSignalSystemController.IDENTIFIER; signalControllerFactoryClassName = DefaultPlanbasedSignalSystemController.FixedTimeFactory.class; @@ -122,7 +122,7 @@ static void fixedTimeSignal(boolean homogenous) throws IOException { } static void adaptiveTimeSignal(boolean homogenous) throws IOException { - outputDirectory = "output/adaptiveTimeSignal/"; + outputDirectory = "output/adaptiveTimeSignal_" + RUN + "/"; if (homogenous) { signalController = LaemmerSignalController.IDENTIFIER; signalControllerFactoryClassName = LaemmerSignalController.LaemmerFactory.class; @@ -166,18 +166,19 @@ static void adaptiveTimeSignal(boolean homogenous) throws IOException { } - public static void compareMixedTrafficSignals(boolean homogenous) throws IOException { + public static void compareTrafficSignals(boolean homogenous) throws IOException { // specify the path to your CSV file - List csvPaths = Arrays.asList("input/low_demand/signal_input.csv", "input/high_demand/signal_input.csv"); + List csvPaths = Arrays.asList("input/low_demand/signal_input.csv"); int index = 0; // create a CSVReader instance String line = ""; String delimiter = ","; boolean isFirstRowRead = true; boolean isFirstRowWrite = true; - for (String csvPath: csvPaths) { +// for (String csvPath: csvPaths) { + String csvPath = csvPaths.get(1); try (BufferedReader br = new BufferedReader(new FileReader(csvPath))) { while ((line = br.readLine()) != null) { @@ -188,18 +189,19 @@ public static void compareMixedTrafficSignals(boolean homogenous) throws IOExcep continue; } // access the values in each column - LANE_LENGTH = Double.parseDouble(values[0]); - LANE_CAPACITY = Integer.parseInt(values[1]); - LINK_LENGTH = Double.parseDouble(values[2]); - LINK_CAPACITY = Integer.parseInt(values[3]); - CYCLE = Integer.parseInt(values[4]); - AGENTS_PER_LEFT_APPROACH = Integer.parseInt(values[5]); - AGENTS_PER_TOP_APPROACH = Integer.parseInt(values[6]); - AGENTS_PER_RIGHT_APPROACH = Integer.parseInt(values[7]); - AGENTS_PER_BOTTOM_APPROACH = Integer.parseInt(values[8]); - ITERATION = Integer.parseInt(values[9]); - STORAGE_CAPACITY_FACTOR = Double.parseDouble(values[10]); - FLOW_CAPACITY_FACTOR = Double.parseDouble(values[11]); + RUN = String.valueOf(values[0]); + LANE_LENGTH = Double.parseDouble(values[1]); + LANE_CAPACITY = Integer.parseInt(values[2]); + LINK_LENGTH = Double.parseDouble(values[3]); + LINK_CAPACITY = Integer.parseInt(values[4]); + CYCLE = Integer.parseInt(values[5]); + AGENTS_PER_LEFT_APPROACH = Integer.parseInt(values[6]); + AGENTS_PER_TOP_APPROACH = Integer.parseInt(values[7]); + AGENTS_PER_RIGHT_APPROACH = Integer.parseInt(values[8]); + AGENTS_PER_BOTTOM_APPROACH = Integer.parseInt(values[9]); + ITERATION = Integer.parseInt(values[10]); + STORAGE_CAPACITY_FACTOR = Double.parseDouble(values[11]); + FLOW_CAPACITY_FACTOR = Double.parseDouble(values[12]); addToBothLists(fixedList, adaptiveList, String.valueOf(LANE_LENGTH)); addToBothLists(fixedList, adaptiveList, String.valueOf(LANE_CAPACITY)); @@ -278,7 +280,6 @@ public static void compareMixedTrafficSignals(boolean homogenous) throws IOExcep } catch (IOException e) { e.printStackTrace(); } - } fixedWriter.close(); adaptiveWriter.close(); diff --git a/src/main/java/playground/shivam/signals/SignalUtils.java b/src/main/java/playground/shivam/signals/SignalUtils.java index 00a7e548..4ffd82f3 100644 --- a/src/main/java/playground/shivam/signals/SignalUtils.java +++ b/src/main/java/playground/shivam/signals/SignalUtils.java @@ -4,6 +4,7 @@ import java.util.Collection; public class SignalUtils { + public static String RUN; public static double LANE_LENGTH; public static int LANE_CAPACITY; public static int NO_LANES = 1; @@ -33,5 +34,5 @@ public class SignalUtils { public static int CYCLE; - public static Collection MAIN_MODES = Arrays.asList("car","truck"); + public static Collection MAIN_MODES = Arrays.asList("car"); } diff --git a/src/main/java/playground/shivam/signals/config/CreateConfig.java b/src/main/java/playground/shivam/signals/config/CreateConfig.java index c8ac55ae..524a2a3a 100644 --- a/src/main/java/playground/shivam/signals/config/CreateConfig.java +++ b/src/main/java/playground/shivam/signals/config/CreateConfig.java @@ -38,10 +38,10 @@ public static Config defineConfig(String outputDirectory, boolean adaptive) thro config.planCalcScore().setWriteExperiencedPlans(true); - config.travelTimeCalculator().setMaxTime(5 * 60 * 60); + config.travelTimeCalculator().setMaxTime(24 * 60 * 60); config.qsim().setStartTime(0); - config.qsim().setEndTime(5 * 60 * 60); + config.qsim().setEndTime(24 * 60 * 60); //config.qsim().setSnapshotStyle(QSimConfigGroup.SnapshotStyle.withHoles); config.qsim().setTrafficDynamics(QSimConfigGroup.TrafficDynamics.withHoles); config.qsim().setMainModes(SignalUtils.MAIN_MODES); @@ -98,10 +98,10 @@ public static Config defineConfig(String outputDirectory, boolean adaptive) thro car.setConstant(-0.5); config.planCalcScore().addModeParams(car); - PlanCalcScoreConfigGroup.ModeParams truck = new PlanCalcScoreConfigGroup.ModeParams("truck"); // using default for them. - truck.setConstant(-1.0); - truck.setMarginalUtilityOfTraveling(-7.0); - config.planCalcScore().addModeParams(truck); +// PlanCalcScoreConfigGroup.ModeParams truck = new PlanCalcScoreConfigGroup.ModeParams("truck"); // using default for them. +// truck.setConstant(-1.0); +// truck.setMarginalUtilityOfTraveling(-7.0); +// config.planCalcScore().addModeParams(truck); if (adaptive) { LaemmerConfigGroup laemmerConfigGroup = ConfigUtils.addOrGetModule(config, LaemmerConfigGroup.GROUP_NAME, LaemmerConfigGroup.class);