[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ondemand #277

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ff4f749
test
CmdrTMir Aug 27, 2022
ce9482e
changed webui
CmdrTMir Aug 29, 2022
e9d6fe0
edges: added ondemand
CmdrTMir Aug 29, 2022
cfdf9e9
criteria ondemand in routing created
CmdrTMir Aug 29, 2022
8999206
added new ondemand label and adjust edges and routing
CmdrTMir Aug 29, 2022
12d49b3
new header file for availability check
CmdrTMir Aug 29, 2022
1c77fe5
created availability check class
CmdrTMir Aug 29, 2022
42acccb
added ondemand to direct con
CmdrTMir Aug 29, 2022
8bb54b2
added ondemand in intermodal
CmdrTMir Aug 30, 2022
438d192
changed area check to boost function
CmdrTMir Aug 30, 2022
f2a1580
created test server and changed ondemand to work with config file
CmdrTMir Sep 3, 2022
6456d60
changed server info handling
CmdrTMir Sep 3, 2022
81321e4
added function for unixtime/traveltime conversion
CmdrTMir Sep 4, 2022
b14e516
fixed read json array function
CmdrTMir Sep 4, 2022
8af64df
fixed direct connections
CmdrTMir Sep 6, 2022
0942b30
changed split ondemand transport
CmdrTMir Sep 6, 2022
558869f
cleaned code to push
CmdrTMir Sep 7, 2022
003b65f
style changes
CmdrTMir Sep 9, 2022
8fee905
style changes
CmdrTMir Sep 9, 2022
6f530b5
style changes and using date lib for time to iso string conversions now
CmdrTMir Sep 9, 2022
5a997d9
style changes
CmdrTMir Sep 10, 2022
01b371a
style changes and usage of date lib for time to string conversion
CmdrTMir Sep 10, 2022
ed11908
style changes
CmdrTMir Sep 12, 2022
b3f9247
improved remove not available journey function
CmdrTMir Sep 12, 2022
32ae8b1
style changes
CmdrTMir Sep 12, 2022
047724d
changed how the ondemand server config is read
CmdrTMir Sep 12, 2022
c8cd216
added statistics for ondemand and fixed split transport for ondemand
CmdrTMir Sep 14, 2022
3d0dc17
style changes
CmdrTMir Sep 14, 2022
243119d
changed apply ondemand patches and remove not available functions
CmdrTMir Sep 15, 2022
daffa38
improved test server and availability checking function
CmdrTMir Sep 16, 2022
652992e
added new ondemand label
CmdrTMir Sep 21, 2022
5af20ef
added more statistics
CmdrTMir Sep 21, 2022
bba10e0
testing and fixes
CmdrTMir Oct 5, 2022
6677020
testing and fixes
CmdrTMir Oct 5, 2022
52c0c01
Cmake changes for testserver
CmdrTMir Oct 6, 2022
97265a1
test server changes, new test server main
CmdrTMir Oct 6, 2022
9b5113a
more test server settings
CmdrTMir Oct 7, 2022
d9201f5
changed statistic measurement
CmdrTMir Oct 8, 2022
55e46e4
added new criteria and new label
CmdrTMir Oct 8, 2022
18677ca
fixed availability check for direct connections
CmdrTMir Oct 10, 2022
959f3e1
fixed some mistakes
CmdrTMir Oct 15, 2022
d4e8cc8
added statistics for parallel compare
CmdrTMir Oct 15, 2022
c6c602c
disabled http-log output
CmdrTMir Oct 15, 2022
508fb81
fixed test server, some minor changes
CmdrTMir Oct 16, 2022
e13d53a
extended read json function for arrays
CmdrTMir Oct 24, 2022
a9d61af
added and changed test server features
CmdrTMir Oct 24, 2022
a8c851c
changed files to have/see more statistic data
CmdrTMir Oct 25, 2022
97be79a
changed settings in test server and comments
CmdrTMir Oct 25, 2022
2fc24d6
fixed criteria
CmdrTMir Oct 26, 2022
ccd0910
added statistics
CmdrTMir Oct 26, 2022
0f41fe3
changed test server and criteria
CmdrTMir Oct 26, 2022
307dc13
changes and fixes for tests
CmdrTMir Oct 28, 2022
ea512dc
minor changes, commit to create new branch for parallel
CmdrTMir Oct 29, 2022
9ea5c34
fixed criteria ondemand with duration cost and added wait to testserver
CmdrTMir Nov 4, 2022
e41e358
changed sleep duration and default thread count
CmdrTMir Nov 6, 2022
42ebb26
cleaned code to push
CmdrTMir Nov 8, 2022
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
Prev Previous commit
Next Next commit
changed area check to boost function
  • Loading branch information
CmdrTMir committed Aug 30, 2022
commit 438d19294c5bb535f4b1df8597439fc589ea6393
125 changes: 39 additions & 86 deletions modules/intermodal/src/ondemand_availability.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

#include "motis/module/context/motis_http_req.h"

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>

using namespace std;
using namespace motis::module;
using namespace motis::json;
Expand All @@ -26,72 +30,6 @@ using namespace rapidjson;
namespace motis::intermodal {
#define DELAY 900 // 15min

bool check_area(vector<Dot> polygon_area, Dot testdot) {
bool res = false;
int poly_size = static_cast<int>(polygon_area.size());
if (poly_size < 3) {
return res;
}
Dot infinity_dot;
infinity_dot.lat = testdot.lat;
infinity_dot.lng = 181;
int result = 0;
int j = 1;
auto alignment = [&](Dot const* point, Dot const* dot,
Dot const* third) -> int {
double val = (dot->lat - point->lat) * (third->lng - dot->lng) -
(dot->lng - point->lng) * (third->lat - dot->lat);
if (val == 0.0) // epsilon ?
{
// collinear
return 0;
}
// 1 - below || 2 - above
return (val > 0.0) ? 1 : 2;
};
auto const* point, Dot const* dot, Dot const* third) -> int {
if (dot->lng <= max(point->lng, third->lng) &&
dot->lng >= min(point->lng, third->lng) &&
dot->lat <= max(point->lat, third->lat) &&
dot->lat >= min(point->lat, third->lat))
return true;
return false;
};
auto find_intersection = [&](Dot const* point_one, Dot const* point_two,
Dot const* test_point,
Dot const* infinity_dot) -> bool {
int orientation1 = alignment(point_one, point_two, test_point);
int orientation2 = alignment(point_one, point_two, infinity_dot);
int orientation3 = alignment(test_point, infinity_dot, point_one);
int orientation4 = alignment(test_point, infinity_dot, point_two);
if (orientation1 != orientation2 && orientation3 != orientation4)
return true;
if (orientation1 == 0 && onLine(point_one, test_point, point_two))
return true;
if (orientation2 == 0 && onLine(point_one, infinity_dot, point_two))
return true;
if (orientation3 == 0 && onLine(test_point, point_one, infinity_dot))
return true;
if (orientation4 == 0 && onLine(test_point, point_two, infinity_dot))
return true;
return false;
};
for (int i = 0; i < poly_size; i++) {
if (find_intersection(&polygon_area[i], &polygon_area[j], &testdot,
&infinity_dot)) {
if (alignment(&polygon_area[i], &testdot, &polygon_area[j]) == 0) {
res = onLine(&polygon_area[i], &testdot, &polygon_area[j]);
return res;
}
result++;
}
j++;
if (j == poly_size) j = 0;
}
res = result % 2 == 1;
return res;
}

availability_response read_result(const response& result, bool first, vector<Dot> dots)
{
printf("read_result\n");
Expand All @@ -113,7 +51,7 @@ availability_response read_result(const response& result, bool first, vector<Dot
docu.GetErrorOffset());
}
auto const& data = get_obj(docu, "data");
auto read_jay_key_string = [&](char const* key, char const* name) -> string
auto read_json_key_string = [&](char const* key, char const* name) -> string
{
auto const it = data.FindMember(key);
if (it != data.MemberEnd() && it->value.IsString())
Expand All @@ -130,7 +68,7 @@ availability_response read_result(const response& result, bool first, vector<Dot
}
return "";
};
auto read_jay_key_int = [&](char const* key, char const* name) -> int
auto read_json_key_int = [&](char const* key, char const* name) -> int
{
auto const it = data.FindMember(key);
if (it != data.MemberEnd() && it->value.IsInt())
Expand All @@ -147,7 +85,7 @@ availability_response read_result(const response& result, bool first, vector<Dot
}
return -1;
};
auto read_jay_key_double = [&](char const* key, char const* name) -> double
auto read_json_key_double = [&](char const* key, char const* name) -> double
{
auto const it = data.FindMember(key);
if (it != data.MemberEnd() && it->value.IsDouble())
Expand All @@ -164,7 +102,7 @@ availability_response read_result(const response& result, bool first, vector<Dot
}
return -1.0;
};
auto read_jay_key_array = [&](char const* key, char const* name) -> vector<vector<double>>
auto read_json_key_array = [&](char const* key, char const* name) -> vector<vector<double>>
{
auto const it = data.FindMember(key);
vector<vector<double>> vec;
Expand Down Expand Up @@ -192,8 +130,8 @@ availability_response read_result(const response& result, bool first, vector<Dot

if(first)
{
ares.codenumber_id = read_jay_key_string("id", " ");
vector<vector<double>> polypoints = read_jay_key_array("area", "coordinates");
ares.codenumber_id = read_json_key_string("id", " ");
vector<vector<double>> polypoints = read_json_key_array("area", "coordinates");
vector<Dot> polygon_area;
polygon_area.resize(polypoints.size());
int k = 0;
Expand All @@ -215,26 +153,41 @@ availability_response read_result(const response& result, bool first, vector<Dot
}
k++;
}
bool inside_start = check_area(polygon_area, dots.at(0));
bool inside_end = check_area(polygon_area, dots.at(1));
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon_type;
point_type point_one(dots.at(0).lat, dots.at(0).lng);
point_type point_two(dots.at(1).lat, dots.at(1).lng);
polygon_type poly;
std::vector<Dot>::iterator it;
for(it = polygon_area.begin(); it != polygon_area.end(); it++)
{
Dot dot = *it;
boost::geometry::append(poly, boost::geometry::make<point_type>(dot.lat, dot.lng));
}
// zwei zeilen falls der erste und letzte punkt nicht übereinstimmen - last dot vorne anhängen?
//Dot last_dot = polygon_area[polygon_area.size()-1];
//boost::geometry::append(poly, boost::geometry::make<point_type>(last_dot.lat, last_dot.lng));
//boost::geometry::correct(poly); // correct the polygon orientation
bool inside_start = boost::geometry::within(point_one, poly);
bool inside_end = boost::geometry::within(point_two, poly);
ares.available = inside_start && inside_end;
return ares;
}
else
{
ares.codenumber_id = read_jay_key_string("id", " ");
ares.startpoint.lat = read_jay_key_double("pickup", "lat");
ares.startpoint.lng = read_jay_key_double("pickup", "lng");
ares.endpoint.lat = read_jay_key_double("dropoff", "lat");
ares.endpoint.lng = read_jay_key_double("dropoff", "lng");
ares.price = read_jay_key_double("fare", "final_price");
ares.walkDur[0] = read_jay_key_int("pickup", "walking_duration");
ares.walkDur[1] = read_jay_key_int("dropoff", "walking_duration");
//string pu_time1 = read_jay_key_string("pickup", "time");
string pu_time2 = read_jay_key_string("pickup", "negotiation_time");
ares.codenumber_id = read_json_key_string("id", " ");
ares.startpoint.lat = read_json_key_double("pickup", "lat");
ares.startpoint.lng = read_json_key_double("pickup", "lng");
ares.endpoint.lat = read_json_key_double("dropoff", "lat");
ares.endpoint.lng = read_json_key_double("dropoff", "lng");
ares.price = read_json_key_double("fare", "final_price");
ares.walkDur[0] = read_json_key_int("pickup", "walking_duration");
ares.walkDur[1] = read_json_key_int("dropoff", "walking_duration");
//string pu_time1 = read_json_key_string("pickup", "time");
string pu_time2 = read_json_key_string("pickup", "negotiation_time");
//string pu_time3 = read_jay_key_string("pickup", "negotiation_time_max");
//string do_time1 = read_jay_key_string("dropoff", "time");
string do_time2 = read_jay_key_string("dropoff", "negotiation_time");
string do_time2 = read_json_key_string("dropoff", "negotiation_time");
//string do_time3 = read_jay_key_string("dropoff", "negotiation_time_max");
//"2017-09-06T15:13:43Z" -> 1504703623
auto traveltime_to_unixtime = [&](const string& timestring) -> int64_t
Expand Down Expand Up @@ -463,7 +416,7 @@ bool checking(const availability_request& areq, const availability_response& are
availability_response check_od_availability(const availability_request areq)
{
printf("check_od_availability!\n");
string addr = "http://127.0.0.1:9000/"; //TESTSERVER
string addr = ""; //TESTSERVER
request::method m = request::GET;
map<string, string> hdrs;
hdrs.insert(pair<string, string>("Accept","application/json"));
Expand Down