Skip to content

Commit

Permalink
fix locale for MPS (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl authored Feb 9, 2024
1 parent eb1990e commit ce146ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++;
}

Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,32 +37,32 @@ 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");

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");
Expand Down

0 comments on commit ce146ac

Please sign in to comment.