-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,879 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
/** | ||
* Enum of network parameters. | ||
*/ | ||
public enum Parameter { | ||
public enum NetworkAttribute { | ||
freespeed, | ||
capacity | ||
} |
53 changes: 53 additions & 0 deletions
53
...s/application/src/main/java/org/matsim/application/prepare/network/opt/NetworkParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.matsim.application.prepare.network.opt; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Object containing parameters for a model. Can be used to serialize and deserialize parameters. | ||
*/ | ||
final class NetworkParams { | ||
|
||
double f; | ||
|
||
@JsonIgnore | ||
Map<String, double[]> params = new HashMap<>(); | ||
|
||
/** | ||
* Used by jackson | ||
*/ | ||
public NetworkParams() { | ||
} | ||
|
||
public NetworkParams(double f) { | ||
this.f = f; | ||
} | ||
|
||
@JsonAnyGetter | ||
public double[] getParams(String type) { | ||
return params.get(type); | ||
} | ||
|
||
@JsonAnySetter | ||
public void setParams(String type, double[] params) { | ||
this.params.put(type, params); | ||
} | ||
|
||
public boolean hasParams() { | ||
return !params.isEmpty(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (f == 0) | ||
return "Request{" + params.entrySet().stream() | ||
.map(e -> e.getKey() + "=" + e.getValue().length).collect(Collectors.joining(",")) + '}'; | ||
|
||
return "Request{f=" + f + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...tion/src/test/java/org/matsim/application/prepare/network/opt/ApplyNetworkParamsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.matsim.application.prepare.network.opt; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.matsim.contrib.sumo.SumoNetworkConverter; | ||
import org.matsim.testcases.MatsimTestUtils; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ApplyNetworkParamsTest { | ||
|
||
@RegisterExtension | ||
MatsimTestUtils utils = new MatsimTestUtils(); | ||
|
||
@Test | ||
void apply() throws Exception { | ||
|
||
Path networkPath = Path.of(utils.getPackageInputDirectory()).resolve("osm.net.xml"); | ||
|
||
Path output = Path.of(utils.getOutputDirectory()); | ||
|
||
SumoNetworkConverter converter = SumoNetworkConverter.newInstance(List.of(networkPath), | ||
output.resolve("network.xml"), | ||
"EPSG:4326", "EPSG:4326"); | ||
|
||
converter.call(); | ||
|
||
assertThat(output.resolve("network.xml")).exists(); | ||
assertThat(output.resolve("network-ft.csv")).exists(); | ||
|
||
new ApplyNetworkParams().execute( | ||
"capacity", "freespeed", | ||
"--network", output.resolve("network.xml").toString(), | ||
"--input-features", output.resolve("network-ft.csv").toString(), | ||
"--output", output.resolve("network-opt.xml").toString(), | ||
"--model", "org.matsim.application.prepare.network.opt.ref.GermanyNetworkParams" | ||
); | ||
|
||
assertThat(output.resolve("network-opt.xml")).exists(); | ||
|
||
} | ||
} |
Oops, something went wrong.