Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dsf_mobility
networkx
numpy
numba
tqdm
23 changes: 21 additions & 2 deletions examples/simulate_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,27 @@
import logging

from dsf.cartography import get_cartography
from dsf.mobility import RoadNetwork, Dynamics, AgentInsertionMethod
from dsf.mobility import (
RoadNetwork,
Dynamics,
AgentInsertionMethod,
PathWeight,
SpeedFunction,
)

from tqdm import trange
from numba import cfunc, float64

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

third party import "from numba import cfunc, float64" should be placed before "from dsf.cartography import get_cartography" Warning

third party import "from numba import cfunc, float64" should be placed before "from dsf.cartography import get_cartography"

Check warning

Code scanning / Prospector (reported by Codacy)

Unable to import 'numba' (import-error) Warning

Unable to import 'numba' (import-error)
import numpy as np
import networkx as nx


@cfunc(float64(float64, float64), nopython=True, cache=True)
def custom_speed(max_speed, density):

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Missing function or method docstring Warning

Missing function or method docstring
if density < 0.35:
return max_speed * (0.9 - 0.1 * density)
return max_speed * (1.2 - 0.7 * density)


logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
Expand Down Expand Up @@ -75,7 +90,11 @@
vehicle_input = np.random.randint(0, 50, size=8640)

# Create a dynamics model for the road network
dynamics = Dynamics(road_network, seed=args.seed, alpha=0.8)
dynamics = Dynamics(road_network, seed=args.seed)

Check warning

Code scanning / Pylint (reported by Codacy)

Constant name "dynamics" doesn't conform to UPPER_CASE naming style Warning

Constant name "dynamics" doesn't conform to UPPER_CASE naming style
dynamics.setWeightFunction(PathWeight.TRAVELTIME)
dynamics.setSpeedFunction(SpeedFunction.LINEAR, 0.8)
# To use a custom speed function, you must pass the pointer to the compiled function using the address attribute

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (116/100) Warning

Line too long (116/100)

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (116/100) Warning

Line too long (116/100)
# dynamics.setSpeedFunction(SpeedFunction.CUSTOM, custom_speed.address)
# Get epoch time of today at midnight
epoch_time = int(
datetime.combine(datetime.today(), datetime.min.time()).timestamp()
Expand Down
4 changes: 1 addition & 3 deletions examples/slow_charge_rb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ int main(int argc, char** argv) {

std::cout << "Creating dynamics...\n";

Dynamics dynamics{graph, false, SEED, 0.6};

Dynamics dynamics{graph, false, SEED};
{
std::vector<dsf::Id> destinationNodes;
for (auto const& [nodeId, pNode] : dynamics.graph().nodes()) {
Expand All @@ -114,7 +113,6 @@ int main(int argc, char** argv) {
dynamics.setErrorProbability(0.05);
dynamics.setPassageProbability(0.7707);
// dynamics.setForcePriorities(true);
dynamics.setSpeedFluctuationSTD(0.1);

// Connect database for saving data
dynamics.connectDataBase(OUT_FOLDER + "simulation_data.db");
Expand Down
3 changes: 1 addition & 2 deletions examples/slow_charge_tl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ int main(int argc, char** argv) {

std::cout << "Creating dynamics...\n";

Dynamics dynamics{graph, false, SEED, 0.6};
Dynamics dynamics{graph, false, SEED};
{
std::vector<dsf::Id> destinationNodes;
for (auto const& [nodeId, pNode] : dynamics.graph().nodes()) {
Expand All @@ -168,7 +168,6 @@ int main(int argc, char** argv) {
dynamics.setErrorProbability(ERROR_PROBABILITY);
// dynamics.setMaxFlowPercentage(0.69);
// dynamics.setForcePriorities(false);
dynamics.setSpeedFluctuationSTD(0.1);
if (OPTIMIZE)
dynamics.setDataUpdatePeriod(30); // Store data every 30 time steps

Expand Down
3 changes: 1 addition & 2 deletions examples/stalingrado.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ int main() {
auto const& coil = graph.edge(19);

// Create the dynamics
FirstOrderDynamics dynamics{graph, false, 69, 0.6};
dynamics.setSpeedFluctuationSTD(0.2);
FirstOrderDynamics dynamics{graph, false, 69};
dynamics.addItinerary(4, 4);
dynamics.updatePaths();

Expand Down
Loading
Loading