Skip to content

Commit

Permalink
Merge branch 'master' into kmt_addCarrierJobInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 authored Dec 2, 2024
2 parents 3263dd2 + b5c1e5b commit 95dee83
Show file tree
Hide file tree
Showing 225 changed files with 36,153 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/full-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
#os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Prepare git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class ApplyNetworkParams implements MATSimAppCommand {
@CommandLine.Option(names = "--model", description = "Reference to the network model class", required = true)
private Class<? extends NetworkModel> modelClazz;

@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower,upper bound)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower, upper bound). " +
"Can be negative to indicate absolute speed bounds (in km/h)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
private double[] speedFactorBounds;

@CommandLine.Option(names = "--capacity-bounds", split = ",", defaultValue = "0.4,0.6,0.8",
Expand Down Expand Up @@ -234,23 +235,40 @@ private boolean applyFreeSpeed(Link link, Feature ft) {
return false;
}

double allowedSpeed = (double) link.getAttributes().getAttribute("allowed_speed");
double freeSpeed = allowedSpeed * speedFactor;

boolean modified = false;

if (speedFactor > speedFactorBounds[1]) {
if (speedFactor > speedFactorBounds[1] && speedFactorBounds[1] >= 0) {
log.warn("Reducing speed factor on {} from {} to {}", link.getId(), speedFactor, speedFactorBounds[1]);
speedFactor = speedFactorBounds[1];
modified = true;
}

// Use absolute bound for speed
if (freeSpeed > -speedFactorBounds[1]/3.6 && speedFactorBounds[1] < 0) {
log.warn("Reducing speed on {} from {} to {}", link.getId(), freeSpeed, -speedFactorBounds[1]/3.6);
speedFactor = (-speedFactorBounds[1] / 3.6) / allowedSpeed;
modified = true;
}

// Threshold for very low speed factors
if (speedFactor < speedFactorBounds[0]) {
if (speedFactor < speedFactorBounds[0] && speedFactorBounds[0] >= 0) {
log.warn("Increasing speed factor on {} from {} to {}", link, speedFactor, speedFactorBounds[0]);
speedFactor = speedFactorBounds[0];
modified = true;
}

double freeSpeed = (double) link.getAttributes().getAttribute("allowed_speed") * speedFactor;
// Absolute negative speed factor
if (freeSpeed < -speedFactorBounds[0]/3.6 && speedFactorBounds[0] < 0) {
log.warn("Increasing speed on {} from {} to {}", link, freeSpeed, -speedFactorBounds[0]/3.6);
speedFactor = (-speedFactorBounds[0] / 3.6) / allowedSpeed;
modified = true;
}

// Recalculate with updated speed factor
freeSpeed = allowedSpeed * speedFactor;
freeSpeed = BigDecimal.valueOf(freeSpeed).setScale(3, RoundingMode.HALF_EVEN).doubleValue();

if (decrease && freeSpeed > link.getFreespeed())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,27 @@ static Result applyAndEvaluateParams(
speedFactor = speedModel.predict(ft.features(), ft.categories());

// apply lower and upper bound
speedFactor = Math.max(speedFactorBounds[0], speedFactor);
speedFactor = Math.min(speedFactorBounds[1], speedFactor);
if (speedFactorBounds[0] >= 0)
speedFactor = Math.max(speedFactorBounds[0], speedFactor);

if (speedFactorBounds[1] >= 0)
speedFactor = Math.min(speedFactorBounds[1], speedFactor);

attributes.put(link.getId(), speedModel.getData(ft.features(), ft.categories()));

link.setFreespeed(allowedSpeed * speedFactor);
double freespeed = allowedSpeed * speedFactor;

// Check absolute bounds on the freespeed
if (speedFactorBounds[0] < 0 && freespeed < -speedFactorBounds[0]/3.6) {
freespeed = -speedFactorBounds[0]/3.6;
speedFactor = freespeed / allowedSpeed;
}
if (speedFactorBounds[1] < 0 && freespeed > -speedFactorBounds[1]/3.6) {
freespeed = -speedFactorBounds[1]/3.6;
speedFactor = freespeed / allowedSpeed;
}

link.setFreespeed(freespeed);
link.getAttributes().putAttribute("speed_factor", speedFactor);

} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public class FreespeedOptServer implements MATSimAppCommand {
@CommandLine.Parameters(arity = "1..*", description = "Input validation files loaded from APIs")
private List<String> validationFiles;

@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower,upper bound)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
@CommandLine.Option(names = "--factor-bounds", split = ",", description = "Speed factor limits (lower, upper bound). " +
"Can be negative to indicate absolute speed bounds (in km/h)", defaultValue = NetworkParamsOpt.DEFAULT_FACTOR_BOUNDS)
private double[] speedFactorBounds;

@CommandLine.Option(names = "--ref-hours", description = "Reference hours", defaultValue = "3,21", split = ",")
Expand Down
19 changes: 17 additions & 2 deletions contribs/freight/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@

# Freight

Package that plugs freight algorithms (programmed in external package jsprit) into matsim.
This contrib contains the following packages:

## Carriers
(This is formally knows as 'freight contrib')

Package that plugs vehicle routing problem algorithms (programmed in external package jsprit) into MATSim.

A good starting point for jsprit is [ https://github.com/graphhopper/jsprit](https://github.com/graphhopper/jsprit).

For runnable code see, e.g., the packages org.matsim.contrib.freight.usecases.* above .
For runnable code see, e.g., the packages org.matsim.contrib.freight.carriers.usecases.* above .

## Logistics
(This code comes from [https://github.com/matsim-vsp/logistics/](https://github.com/matsim-vsp/logistics/) )

This code deals with creating logistics chains for freight transport.

Here the decision agent is the logistics service provider (LSP) who decides on the logistics chain to be used for a given freight transport request.
Therefore, it can use carriers (see above) and hubs.

This package bases on work in the dfg-freight project.


Loading

0 comments on commit 95dee83

Please sign in to comment.