From ce146acc15610eef2cf68cdcbae1caaea5a932c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Fri, 9 Feb 2024 10:36:10 +0100 Subject: [PATCH] fix locale for MPS (#34) --- .../assignment/MpsAssignmentWriter.java | 21 ++++++++++--------- .../relocation/MpsRelocationWriter.java | 15 ++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java index 8572fae..e56cceb 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/assignment/MpsAssignmentWriter.java @@ -7,6 +7,7 @@ import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; @@ -48,18 +49,18 @@ public void write(File path) throws IOException { int rowIndex = 0; - writer.write(String.format(" N R%07d\n", rowIndex)); + writer.write(String.format(Locale.US, " N R%07d\n", rowIndex)); rowIndex++; // <= 1 rows for the vehicles for (int i = 0; i < numberOfVehicles; i++) { - writer.write(String.format(" L R%07d\n", rowIndex)); + writer.write(String.format(Locale.US, " L R%07d\n", rowIndex)); rowIndex++; } // == 1 rows for the requests for (int i = 0; i < numberOfRequests; i++) { - writer.write(String.format(" E R%07d\n", rowIndex)); + writer.write(String.format(Locale.US, " E R%07d\n", rowIndex)); rowIndex++; } @@ -69,40 +70,40 @@ public void write(File path) throws IOException { // Trip influences for (int i = 0; i < numberOfTrips; i++) { AlonsoMoraTrip trip = tripList.get(i); - writer.write(String.format(" T%d R%07d %f\n", i, 0, trip.getResult().getCost())); + writer.write(String.format(Locale.US, " T%d R%07d %f\n", i, 0, trip.getResult().getCost())); int vehicleIndex = vehicleList.indexOf(trip.getVehicle()); - writer.write(String.format(" T%d R%07d 1\n", i, vehicleIndex + 1)); + writer.write(String.format(Locale.US, " T%d R%07d 1\n", i, vehicleIndex + 1)); for (AlonsoMoraRequest request : trip.getRequests()) { int requestIndex = requestList.indexOf(request); - writer.write(String.format(" T%d R%07d 1\n", i, requestIndex + numberOfVehicles + 1)); + writer.write(String.format(Locale.US, " T%d R%07d 1\n", i, requestIndex + numberOfVehicles + 1)); } } // Request influences for (int i = 0; i < numberOfRequests; i++) { double penalty = requestList.get(i).isAssigned() ? unassignmentPenalty : rejectionPenalty; - writer.write(String.format(" x%d R%07d %f R%07d 1\n", i, 0, penalty, i + numberOfVehicles + 1)); + writer.write(String.format(Locale.US, " x%d R%07d %f R%07d 1\n", i, 0, penalty, i + numberOfVehicles + 1)); } writer.write(" M0000002 'MARKER' 'INTEND'\n"); writer.write("RHS\n"); for (int i = 0; i < numberOfVehicles + numberOfRequests; i++) { - writer.write(String.format(" RHS1 R%07d 1\n", i + 1)); + writer.write(String.format(Locale.US, " RHS1 R%07d 1\n", i + 1)); } writer.write("BOUNDS\n"); // Trip variables bounds for (int i = 0; i < numberOfTrips; i++) { - writer.write(String.format(" UP BND1 T%d 1\n", i)); + writer.write(String.format(Locale.US, " UP BND1 T%d 1\n", i)); } // Trip variables bounds for (int i = 0; i < numberOfRequests; i++) { - writer.write(String.format(" UP BND1 x%d 1\n", i)); + writer.write(String.format(Locale.US, " UP BND1 x%d 1\n", i)); } writer.write("ENDATA\n"); diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriter.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriter.java index 493f8e3..9091e61 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriter.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriter.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; @@ -36,10 +37,10 @@ public void write(File path) throws IOException { writer.write("ROWS\n"); // Objective - writer.write(String.format(" N R%07d\n", 0)); + writer.write(String.format(Locale.US, " N R%07d\n", 0)); // Constraint (equality) - writer.write(String.format(" E R%07d\n", 1)); + writer.write(String.format(Locale.US, " E R%07d\n", 1)); writer.write("COLUMNS\n"); writer.write(" M0000001 'MARKER' 'INTORG'\n"); @@ -47,21 +48,21 @@ public void write(File path) throws IOException { for (int i = 0; i < numberOfVariables; i++) { // Objective Relocation relocation = relocations.get(i); - writer.write(String.format(" T%d R%07d %f", i, 0, relocation.cost)); + writer.write(String.format(Locale.US, " T%d R%07d %f", i, 0, relocation.cost)); // Constraint - writer.write(String.format(" R%07d 1\n", 1)); + writer.write(String.format(Locale.US, " R%07d 1\n", 1)); } writer.write(" M0000002 'MARKER' 'INTEND'\n"); writer.write("RHS\n"); - writer.write(String.format(" RHS1 R%07d %d\n", 1, numberOfAssignments)); + writer.write(String.format(Locale.US, " RHS1 R%07d %d\n", 1, numberOfAssignments)); writer.write("BOUNDS\n"); for (int i = 0; i < numberOfVariables; i++) { - writer.write(String.format(" UP BND1 T%d 1\n", i)); - writer.write(String.format(" LO BND1 T%d 0\n", i)); + writer.write(String.format(Locale.US, " UP BND1 T%d 1\n", i)); + writer.write(String.format(Locale.US, " LO BND1 T%d 0\n", i)); } writer.write("ENDATA\n");