Skip to content

Commit

Permalink
new changes 8.05.2023
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-a committed May 10, 2023
1 parent a135b63 commit 9ea8431
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
41 changes: 21 additions & 20 deletions src/main/java/playground/shivam/signals/RunSignals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -75,15 +75,15 @@ public static void main(String[] args) throws IOException {
adaptiveTimeSignal(true);
break;
case 6:
compareMixedTrafficSignals(true);
compareTrafficSignals(true);
default:
System.out.println("You have exited");
}
} while (a != 0);
}

static void fixedTimeSignal(boolean homogenous) throws IOException {
outputDirectory = "output/fixedTimeSignal/";
outputDirectory = "output/fixedTimeSignal_" + RUN + "/" ;
signalController = DefaultPlanbasedSignalSystemController.IDENTIFIER;
signalControllerFactoryClassName = DefaultPlanbasedSignalSystemController.FixedTimeFactory.class;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> csvPaths = Arrays.asList("input/low_demand/signal_input.csv", "input/high_demand/signal_input.csv");
List<String> 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) {

Expand All @@ -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));
Expand Down Expand Up @@ -278,7 +280,6 @@ public static void compareMixedTrafficSignals(boolean homogenous) throws IOExcep
} catch (IOException e) {
e.printStackTrace();
}
}

fixedWriter.close();
adaptiveWriter.close();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/playground/shivam/signals/SignalUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,5 +34,5 @@ public class SignalUtils {
public static int CYCLE;


public static Collection<String> MAIN_MODES = Arrays.asList("car","truck");
public static Collection<String> MAIN_MODES = Arrays.asList("car");
}
12 changes: 6 additions & 6 deletions src/main/java/playground/shivam/signals/config/CreateConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9ea8431

Please sign in to comment.