From af015b8361a7265b8206c48d6beb9514250f8ec9 Mon Sep 17 00:00:00 2001
From: "ruben.haag" <ruben.haag@stud.uni-goettingen.de>
Date: Mon, 22 Nov 2021 11:13:01 +0100
Subject: [PATCH] v1 NOT WORKING YET

---
 Manifest.toml   | 143 ++++++++++++++++++++++++++++++++++++++++++++++++
 Project.toml    |   2 +
 initialize.jl   |  83 ++++++++++++++++++++++++++++
 put_together.jl |  11 ++++
 run_1d.sh       |  10 ++++
 sim.jl          |  29 ++++++++++
 6 files changed, 278 insertions(+)
 create mode 100644 Manifest.toml
 create mode 100644 Project.toml
 create mode 100644 initialize.jl
 create mode 100644 put_together.jl
 create mode 100644 run_1d.sh
 create mode 100644 sim.jl

diff --git a/Manifest.toml b/Manifest.toml
new file mode 100644
index 0000000..c347ae2
--- /dev/null
+++ b/Manifest.toml
@@ -0,0 +1,143 @@
+# This file is machine-generated - editing it directly is not advised
+
+[[Base64]]
+uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
+
+[[CSV]]
+deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings"]
+git-tree-sha1 = "49f14b6c56a2da47608fe30aed711b5882264d7a"
+uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
+version = "0.9.11"
+
+[[CodecZlib]]
+deps = ["TranscodingStreams", "Zlib_jll"]
+git-tree-sha1 = "ded953804d019afa9a3f98981d99b33e3db7b6da"
+uuid = "944b1d66-785c-5afd-91f1-9de20f533193"
+version = "0.7.0"
+
+[[DataAPI]]
+git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8"
+uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
+version = "1.9.0"
+
+[[DataValueInterfaces]]
+git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
+uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464"
+version = "1.0.0"
+
+[[Dates]]
+deps = ["Printf"]
+uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
+
+[[FilePathsBase]]
+deps = ["Dates", "Mmap", "Printf", "Test", "UUIDs"]
+git-tree-sha1 = "618835ab81e4a40acf215c98768978d82abc5d97"
+uuid = "48062228-2e41-5def-b9a4-89aafe57970f"
+version = "0.9.16"
+
+[[Future]]
+deps = ["Random"]
+uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
+
+[[InlineStrings]]
+deps = ["Parsers"]
+git-tree-sha1 = "19cb49649f8c41de7fea32d089d37de917b553da"
+uuid = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48"
+version = "1.0.1"
+
+[[InteractiveUtils]]
+deps = ["Markdown"]
+uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
+
+[[IteratorInterfaceExtensions]]
+git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856"
+uuid = "82899510-4779-5014-852e-03e436cf321d"
+version = "1.0.0"
+
+[[Libdl]]
+uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
+
+[[LinearAlgebra]]
+deps = ["Libdl"]
+uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
+
+[[Logging]]
+uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
+
+[[Markdown]]
+deps = ["Base64"]
+uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
+
+[[Mmap]]
+uuid = "a63ad114-7e13-5084-954f-fe012c677804"
+
+[[Parsers]]
+deps = ["Dates"]
+git-tree-sha1 = "ae4bbcadb2906ccc085cf52ac286dc1377dceccc"
+uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
+version = "2.1.2"
+
+[[PooledArrays]]
+deps = ["DataAPI", "Future"]
+git-tree-sha1 = "a193d6ad9c45ada72c14b731a318bedd3c2f00cf"
+uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
+version = "1.3.0"
+
+[[Printf]]
+deps = ["Unicode"]
+uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
+
+[[Random]]
+deps = ["Serialization"]
+uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
+
+[[SHA]]
+uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
+
+[[SentinelArrays]]
+deps = ["Dates", "Random"]
+git-tree-sha1 = "f45b34656397a1f6e729901dc9ef679610bd12b5"
+uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c"
+version = "1.3.8"
+
+[[Serialization]]
+uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
+
+[[TableTraits]]
+deps = ["IteratorInterfaceExtensions"]
+git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39"
+uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
+version = "1.0.1"
+
+[[Tables]]
+deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
+git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0"
+uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
+version = "1.6.0"
+
+[[Test]]
+deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
+uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
+
+[[TranscodingStreams]]
+deps = ["Random", "Test"]
+git-tree-sha1 = "216b95ea110b5972db65aa90f88d8d89dcb8851c"
+uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
+version = "0.9.6"
+
+[[UUIDs]]
+deps = ["Random", "SHA"]
+uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
+
+[[Unicode]]
+uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
+
+[[WeakRefStrings]]
+deps = ["DataAPI", "InlineStrings", "Parsers"]
+git-tree-sha1 = "c69f9da3ff2f4f02e811c3323c22e5dfcb584cfa"
+uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5"
+version = "1.4.1"
+
+[[Zlib_jll]]
+deps = ["Libdl"]
+uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
diff --git a/Project.toml b/Project.toml
new file mode 100644
index 0000000..fb505e1
--- /dev/null
+++ b/Project.toml
@@ -0,0 +1,2 @@
+[deps]
+CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
diff --git a/initialize.jl b/initialize.jl
new file mode 100644
index 0000000..4e8e7ca
--- /dev/null
+++ b/initialize.jl
@@ -0,0 +1,83 @@
+export data_functions, save_path, getValues
+
+include("../RidePooling/src/RidePooling.jl")
+RP = RidePooling
+
+# Calculate Route Matrix for Map
+#map=(:star_grid_map,(10,10))
+map_specs=(:grid_highway_map,(4,20,(23,58),2.0))
+#map_specs=(:star_grid_map,(12,12))
+#map_specs=(:grid_map,(8,8))
+#map_specs=(:osm,"/project.dcf/poss/datasets/RidePooling/line_no7_customdict/map/")
+#map_specs=(:osm,"../maps/example_map/")
+mymap = RP.get_map(map_specs)
+RM = RP.calculate_route_matrix(mymap);
+
+
+data_type_functions = Dict(
+    :served_percentage => RP.served_percentage,
+    :driven_distance => RP.driven_distance,
+    :requested_distance => RP.requested_distance,
+    :mean_relative_delay => RP.mean_relative_delay,
+    :mean_occupancy => RP.mean_occupancy,
+)
+
+
+save_path = "" #TODO What savepath?
+
+function getValue(index, xmin, xmax, xlen, ymin, ymax, ylen)
+    xstep = (xmax-xmin)/xlen
+    ystep = (ymax-ymin)/ylen
+    xs = xmin:xstep:xmax
+    ys = ymin:ystep:ymax
+
+    x = xs[index%xlen + 1]
+    y = ys[index - index%xlen + 1]
+    return x,y
+end
+
+function simulation(path;         # Name of the File where the Model should be saved
+        request_type::Symbol = :now,   # one of (:now, :earliest_pickup, :latest_dropoff, :random)
+        ν = 1/60,                #Request frequency
+        N_busses = 3,                  # Number of N_busses
+        time_step = 0.0,
+        rejection_criterion=((:any_relative_detour,max_detour)),
+        t_max_to_early::Float64,
+        dt_pickup, #Has to be iterable
+        dt_dropoff, # Has to be itarable
+        speed_dict=Dict(1=>3.6, 2=>70.0, 3=>50.0, 4=>50.0, 5=>50.0, 6=>30.0, 7=>30.0, 8=>30.0),
+        map_specs=(:star_grid_map,(12,12)),
+        requested=220,
+        served=200,
+        cost=:trajectory_length)
+    route_matrix = get_route_matrix("./");
+
+    #Make Model
+    model=RP.get_model(;\
+        N_bus=N_busses,   #number of buses
+        ν=\nu,    #request frequency [1/s] - default 1 per minute
+        map=mymap,   #OSM map
+        route_matrix=rout_matrix,
+        time_step=0.0
+        subspaces=:all_edges,  #pregenerated subspace tuple. if ==:all_nodes, we draw from the set of all nodes. default: area uniform within map's bounds.
+        rejection_criterion=rejection_criterion,
+        routing=:lookup,
+        speed_dict=speed_dict,
+        cost=cost,
+        request_type= request_type,
+        t_max_wait = t_max_wait,
+        t_max_to_early = t_max_to_early,
+    );
+    RP.run!(model;requested=requested, served=served)
+    data = Dict()
+    for (name, func) in data_functions
+        data[name] = [func(model),]
+    end
+
+    # Save the calculated Data
+    data = DataFrame(data)
+    CSV.write(path * "data.csv") #QUESTION what savepath
+
+    #Save the model for possible later reference
+    RP.savemodel(path* "final.model",model;route_matrix=false) #QUESTION What savepath
+end
diff --git a/put_together.jl b/put_together.jl
new file mode 100644
index 0000000..885c0ab
--- /dev/null
+++ b/put_together.jl
@@ -0,0 +1,11 @@
+
+
+
+for index in indxes
+    #TODO put all the generated CSV Files together into one big file which is then saved to the correct location
+end
+
+
+#TODO put all the generated models in an archive file and save it to the archiving location
+
+#TODO make Plots from the CSV file
diff --git a/run_1d.sh b/run_1d.sh
new file mode 100644
index 0000000..472899d
--- /dev/null
+++ b/run_1d.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+#$ -S /bin/bash
+#$ -cwd
+#$ -q titan.q
+#$ -j yes
+#$ -N myBunchOfSimulations
+#$ -t 1-2082
+
+/usr/dcf/julia-1.5.2/bin/julia scripts/myJuliaScript.jl $SGE_TASK_ID
diff --git a/sim.jl b/sim.jl
new file mode 100644
index 0000000..70ae12c
--- /dev/null
+++ b/sim.jl
@@ -0,0 +1,29 @@
+using Pkg
+Pkg.activate(".")
+Pkg.instantiate()   #there may be an error here concerning PyCall. The dependencies assume Python to be installed on your system, with package 'matplotlib' installed.
+                    #Either just run 'conda install -c conda-forge matplotlib' in your system shell, or follow instructions below (after running this cell and getting an error) to solve everything from within Julia.
+
+using RidePooling
+using DataFrames
+using CSV
+include("./initialize.jl")
+data_functions = initialize.data_functions
+simulation = initialize.simulation
+get_value = initialize.get_value
+
+
+
+
+
+
+
+
+
+index=eval(Meta.parse(ARGS[1]))
+
+
+
+t0 = 60
+x, y = getValue(index, 0, 100, 2, 1/t0, 20/t0, 2)
+
+data = simulation("results/data/$(index)/", request_type=:earliest_pickup, dt_earliest_pickup = x, ν=y)
-- 
GitLab