diff --git a/VadereModelTests/TestOSM/scenarios/basic_1_chicken_osm1.scenario b/VadereModelTests/TestOSM/scenarios/basic_1_chicken_osm1.scenario index 05de929adc8c0408d886ffc9ca01961d9a5b3b74..ed9bb67e0859b55672e445cb7e65276b05a4b5af 100644 --- a/VadereModelTests/TestOSM/scenarios/basic_1_chicken_osm1.scenario +++ b/VadereModelTests/TestOSM/scenarios/basic_1_chicken_osm1.scenario @@ -474,6 +474,1086 @@ } ] }, "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 0.5001 + }, { + "x" : -1.0E-4, + "y" : 0.5001 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : -1.0E-4 + }, { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : 60.0001 + }, { + "x" : 34.4999, + "y" : -1.0E-4 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : 35.0001, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : 59.4999 + }, { + "x" : 35.0001, + "y" : 59.4999 + } ] + }, + "id" : -1 + }, { + "shape" : { + "type" : "POLYGON", + "points" : [ { + "x" : -1.0E-4, + "y" : 60.0001 + }, { + "x" : -1.0E-4, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : -1.0E-4 + }, { + "x" : 0.5001, + "y" : 60.0001 + } ] + }, + "id" : -1 } ], "stairs" : [ ], "targets" : [ { @@ -505,7 +1585,7 @@ }, "interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution", "distributionParameters" : [ 1.0 ], - "spawnNumber" : 200, + "spawnNumber" : 300, "maxSpawnNumberTotal" : -1, "startTime" : 0.0, "endTime" : 0.0, diff --git a/VadereSimulator/src/org/vadere/simulator/control/Simulation.java b/VadereSimulator/src/org/vadere/simulator/control/Simulation.java index 9d7844284632da015ae2e62e800109a80308f1bd..cc8e7d253c163749e2dcd514e958a82f96674623 100644 --- a/VadereSimulator/src/org/vadere/simulator/control/Simulation.java +++ b/VadereSimulator/src/org/vadere/simulator/control/Simulation.java @@ -6,19 +6,26 @@ import org.vadere.simulator.models.DynamicElementFactory; import org.vadere.simulator.models.MainModel; import org.vadere.simulator.models.Model; import org.vadere.simulator.models.potential.PotentialFieldModel; +import org.vadere.simulator.models.potential.fields.IPotentialField; import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget; +import org.vadere.simulator.models.potential.fields.ObstacleDistancePotential; import org.vadere.simulator.projects.ScenarioStore; import org.vadere.simulator.projects.dataprocessing.ProcessorManager; import org.vadere.state.attributes.AttributesSimulation; +import org.vadere.state.attributes.models.AttributesFloorField; import org.vadere.state.attributes.scenario.AttributesAgent; import org.vadere.state.scenario.Source; import org.vadere.state.scenario.Target; import org.vadere.state.scenario.Topography; +import org.vadere.util.geometry.shapes.VPoint; +import org.vadere.util.geometry.shapes.VRectangle; import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Random; +import java.util.function.Function; +import java.util.stream.Collectors; public class Simulation { @@ -72,6 +79,13 @@ public class Simulation { this.targetControllers = new LinkedList<>(); this.topography = scenarioStore.topography; + IPotentialField distanceField = new ObstacleDistancePotential( + topography.getObstacles().stream().map(obs -> obs.getShape()).collect(Collectors.toList()), + new VRectangle(topography.getBounds()), + new AttributesFloorField()); + Function obstacleDistance = p -> distanceField.getPotential(p, null); + this.topography.setObstacleDistanceFunction(obstacleDistance); + this.runTimeInSec = attributesSimulation.getFinishTime(); this.startTimeInSec = startTimeInSec; this.simTimeInSec = startTimeInSec; diff --git a/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldObstacleCompactSoftshell.java b/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldObstacleCompactSoftshell.java index b2678cfe133d260f40daf9c5b42197da199bee19..9aeaeca74c0983d2ede7899bb7a1a4f653ae976e 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldObstacleCompactSoftshell.java +++ b/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldObstacleCompactSoftshell.java @@ -24,25 +24,27 @@ public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObs private double width; private double height; private Collection obstacles; + private Topography topography; public PotentialFieldObstacleCompactSoftshell(AttributesPotentialCompactSoftshell attributesPotential, - Collection obstacles, Random random) { + Topography topography, Random random) { this.attributes = attributesPotential; this.random = random; this.width = attributesPotential.getObstPotentialWidth(); this.height = attributesPotential.getObstPotentialHeight(); - - this.obstacles = obstacles; + this.topography = topography; + this.obstacles = topography.getObstacles(); } @Override public double getObstaclePotential(VPoint pos, Agent pedestrian) { double potential = 0; - for (Obstacle obstacle : obstacles) { + //for (Obstacle obstacle : obstacles) { - double distance = obstacle.getShape().distance(pos); + //double distance = obstacle.getShape().distance(pos); + double distance = topography.distanceToObstacle(pos); double radius = pedestrian.getRadius(); double currentPotential = 0; @@ -56,7 +58,7 @@ public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObs if (potential < currentPotential) potential = currentPotential; - } + //} return potential; } @@ -69,7 +71,7 @@ public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObs @Override public PotentialFieldObstacle copy() { - return new PotentialFieldObstacleCompactSoftshell(attributes, new LinkedList<>(obstacles), random); + return new PotentialFieldObstacleCompactSoftshell(attributes, topography, random); } @Override diff --git a/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldPedestrianCompactSoftshell.java b/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldPedestrianCompactSoftshell.java index a4eb8e95b35d979ddf04e8728bf43583b75f2c60..82ced381e5e2380d13face8f5765e66eebfc1989 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldPedestrianCompactSoftshell.java +++ b/VadereSimulator/src/org/vadere/simulator/models/potential/PotentialFieldPedestrianCompactSoftshell.java @@ -47,25 +47,29 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA @Override public double getAgentPotential(VPoint pos, Agent pedestrian, Agent otherPedestrian) { - double distance = otherPedestrian.getPosition().distance(pos); - - int intPower = this.attributes.getIntimateSpacePower(); - int perPower = this.attributes.getPersonalSpacePower(); - double factor = this.attributes.getIntimateSpaceFactor(); + double radii = pedestrian.getRadius() + otherPedestrian.getRadius(); double potential = 0; + double distnaceSq = otherPedestrian.getPosition().distanceSq(pos); + double maxDistanceSq = (Math.max(personalWidth, intimateWidth) + radii) * (Math.max(personalWidth, intimateWidth) + radii); - double radii = pedestrian.getRadius() + otherPedestrian.getRadius(); + if(distnaceSq < maxDistanceSq) { + double distance = otherPedestrian.getPosition().distance(pos); - if (distance < personalWidth + radii) { - potential += this.height * Math.exp(4 / (Math.pow(distance / (personalWidth + radii), (2 * perPower)) - 1)); - } - if (distance < this.intimateWidth + radii) { - potential += this.height / factor - * Math.exp(4 / (Math.pow(distance / (this.intimateWidth + radii), (2 * intPower)) - 1)); - } - if (distance < radii) { - potential += 1000 * Math.exp(1 / (Math.pow(distance / radii, 4) - 1)); + int intPower = this.attributes.getIntimateSpacePower(); + int perPower = this.attributes.getPersonalSpacePower(); + double factor = this.attributes.getIntimateSpaceFactor(); + + if (distance < personalWidth + radii) { + potential += this.height * Math.exp(4 / (Math.pow(distance / (personalWidth + radii), (2 * perPower)) - 1)); + } + if (distance < this.intimateWidth + radii) { + potential += this.height / factor + * Math.exp(4 / (Math.pow(distance / (this.intimateWidth + radii), (2 * intPower)) - 1)); + } + if (distance < radii) { + potential += 1000 * Math.exp(1 / (Math.pow(distance / radii, 4) - 1)); + } } return potential; diff --git a/VadereSimulator/src/org/vadere/simulator/models/potential/fields/AbstractPotentialFieldTarget.java b/VadereSimulator/src/org/vadere/simulator/models/potential/fields/AbstractPotentialFieldTarget.java index c2c9176b1bc778dc4311046a5f9f8c206bac1503..2367819e6928c68fdf41e685b203f3dfc20bd347 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/potential/fields/AbstractPotentialFieldTarget.java +++ b/VadereSimulator/src/org/vadere/simulator/models/potential/fields/AbstractPotentialFieldTarget.java @@ -62,16 +62,18 @@ public abstract class AbstractPotentialFieldTarget implements IPotentialFieldTar int targetId = agent.getNextTargetId(); // the agent has reached his current target - if (topography.getTarget(targetId).getShape().contains(pos)) { + // TODO: expensive operation + /*if (topography.getTarget(targetId).getShape().contains(pos)) { return 0.0; - } + }*/ // the agent is inside an obstacle - for (ScenarioElement b : topography.getObstacles()) { + // TODO: expensive operation + /*for (ScenarioElement b : topography.getObstacles()) { if (b.getShape().contains(pos)) { return Double.MAX_VALUE; } - } + }*/ /* Find minimal potential of given targets. */ Optional optionalPotentialFieldAndAnalyser = getPotentialFieldAndInitializer(targetId); diff --git a/VadereSimulator/src/org/vadere/simulator/models/potential/fields/ObstacleDistancePotential.java b/VadereSimulator/src/org/vadere/simulator/models/potential/fields/ObstacleDistancePotential.java new file mode 100644 index 0000000000000000000000000000000000000000..210aa9a43b0b167946acb917135da85b09b95e03 --- /dev/null +++ b/VadereSimulator/src/org/vadere/simulator/models/potential/fields/ObstacleDistancePotential.java @@ -0,0 +1,69 @@ +package org.vadere.simulator.models.potential.fields; + +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.vadere.state.attributes.models.AttributesFloorField; +import org.vadere.state.scenario.Agent; +import org.vadere.util.geometry.shapes.VPoint; +import org.vadere.util.geometry.shapes.VRectangle; +import org.vadere.util.geometry.shapes.VShape; +import org.vadere.util.potential.CellGrid; +import org.vadere.util.potential.CellState; +import org.vadere.util.potential.FloorDiscretizer; +import org.vadere.util.potential.PathFindingTag; +import org.vadere.util.potential.calculators.EikonalSolver; +import org.vadere.util.potential.calculators.EikonalSolverFIM; +import org.vadere.util.potential.calculators.EikonalSolverFMM; +import org.vadere.util.potential.calculators.EikonalSolverFSM; +import org.vadere.util.potential.calculators.PotentialFieldCalculatorNone; +import org.vadere.util.potential.timecost.UnitTimeCostFunction; + +import java.util.Collection; + +/** + * @author Benedikt Zoennchen + */ +public class ObstacleDistancePotential implements IPotentialField { + + private static Logger logger = LogManager.getLogger(ObstacleDistancePotential.class); + private final EikonalSolver eikonalSolver; + + public ObstacleDistancePotential(@NotNull final Collection obstacles, + @NotNull final VRectangle bounds, + @NotNull final AttributesFloorField attributesFloorField) { + CellGrid cellGrid = new CellGrid(bounds.getWidth(), bounds.getHeight(), attributesFloorField.getPotentialFieldResolution(), new CellState()); + + for (VShape shape : obstacles) { + FloorDiscretizer.setGridValuesForShapeCentered(cellGrid, shape, + new CellState(0.0, PathFindingTag.Target)); + } + + boolean isHighAccuracyFM = attributesFloorField.getCreateMethod().isHighAccuracy(); + + /* copy the static grid */ + switch (attributesFloorField.getCreateMethod()) { + case NONE: + eikonalSolver = new PotentialFieldCalculatorNone(); + break; + case FAST_ITERATIVE_METHOD: + eikonalSolver = new EikonalSolverFIM(cellGrid, obstacles, isHighAccuracyFM, new UnitTimeCostFunction()); + break; + case FAST_SWEEPING_METHOD: + eikonalSolver = new EikonalSolverFSM(cellGrid, obstacles, isHighAccuracyFM, new UnitTimeCostFunction()); + break; + default: + eikonalSolver = new EikonalSolverFMM(cellGrid, obstacles, isHighAccuracyFM, new UnitTimeCostFunction()); + } + + long ms = System.currentTimeMillis(); + eikonalSolver.initialize(); + logger.info("floor field initialization time:" + (System.currentTimeMillis() - ms + "[ms]")); + } + + @Override + public double getPotential(@NotNull VPoint pos, @Nullable Agent agent) { + return eikonalSolver.getPotential(pos, 0.0, 1.0); + } +} diff --git a/VadereSimulator/src/org/vadere/simulator/models/potential/fields/PotentialFieldObstacle.java b/VadereSimulator/src/org/vadere/simulator/models/potential/fields/PotentialFieldObstacle.java index f2c0762be0a42ac46ce64c3f3e42e9dcb2375f60..17eb57803588f13aed3c0a309c04e3f9adc1b14f 100644 --- a/VadereSimulator/src/org/vadere/simulator/models/potential/fields/PotentialFieldObstacle.java +++ b/VadereSimulator/src/org/vadere/simulator/models/potential/fields/PotentialFieldObstacle.java @@ -77,7 +77,7 @@ public interface PotentialFieldObstacle extends Model { AttributesPotentialCompactSoftshell attributesPotentialCompactSoftshell = Model.findAttributes(modelAttributesList, AttributesPotentialCompactSoftshell.class); result = new PotentialFieldObstacleCompactSoftshell(attributesPotentialCompactSoftshell, - topography.getObstacles(), random); + topography, random); } else { throw new VadereClassNotFoundException(); } diff --git a/VadereState/src/org/vadere/state/scenario/Topography.java b/VadereState/src/org/vadere/state/scenario/Topography.java index 024ab3a3e138bcfe122bfb547811eaf888638508..2f8166d4a5fe81d0c118078d30173cae5b8a2ce3 100644 --- a/VadereState/src/org/vadere/state/scenario/Topography.java +++ b/VadereState/src/org/vadere/state/scenario/Topography.java @@ -10,10 +10,12 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Function; import java.util.function.Predicate; import java.util.stream.Collectors; import org.apache.log4j.Logger; +import org.jetbrains.annotations.NotNull; import org.vadere.state.attributes.Attributes; import org.vadere.state.attributes.scenario.AttributesAgent; import org.vadere.state.attributes.scenario.AttributesCar; @@ -23,11 +25,13 @@ import org.vadere.util.geometry.LinkedCellsGrid; import org.vadere.util.geometry.shapes.VPoint; import org.vadere.util.geometry.shapes.VShape; -@JsonIgnoreProperties(value = {"allOtherAttributes"}) +@JsonIgnoreProperties(value = {"allOtherAttributes", "obstacleDistanceFunction"}) public class Topography { /** Transient to prevent JSON serialization. */ private static Logger logger = Logger.getLogger(Topography.class); + + private Function obstacleDistanceFunction; // TODO [priority=low] [task=feature] magic number, use attributes / parameter? /** @@ -74,7 +78,9 @@ public class Topography { /** Used to store links to all attributes that are not part of scenario elements. */ private Set allOtherAttributes = new HashSet<>(); // will be filled in the constructor - public Topography(AttributesTopography attributes, AttributesAgent attributesPedestrian, + public Topography( + AttributesTopography attributes, + AttributesAgent attributesPedestrian, AttributesCar attributesCar) { this.attributes = attributes; @@ -106,6 +112,8 @@ public class Topography { this.pedestrians = new DynamicElementContainer<>(bounds, CELL_SIZE); this.cars = new DynamicElementContainer<>(bounds, CELL_SIZE); + + this.obstacleDistanceFunction = p -> obstacles.stream().map(obs -> obs.getShape()).map(shape -> shape.distance(p)).min(Double::compareTo).orElse(Double.MAX_VALUE); } @@ -136,6 +144,14 @@ public class Topography { return null; } + public double distanceToObstacle(@NotNull VPoint point) { + return this.obstacleDistanceFunction.apply(point); + } + + public void setObstacleDistanceFunction(@NotNull Function obstacleDistanceFunction) { + this.obstacleDistanceFunction = obstacleDistanceFunction; + } + public boolean containsTarget(final Predicate targetPredicate) { return getTargets().stream().anyMatch(targetPredicate); } diff --git a/VadereUtils/src/org/vadere/util/geometry/shapes/VPoint.java b/VadereUtils/src/org/vadere/util/geometry/shapes/VPoint.java index fcb41fe299a97f5e8f2b44ed1e1842ae3c39e172..55dd0cadd52ecafbcac2cddb9f9c8ffa2d259924 100644 --- a/VadereUtils/src/org/vadere/util/geometry/shapes/VPoint.java +++ b/VadereUtils/src/org/vadere/util/geometry/shapes/VPoint.java @@ -39,6 +39,10 @@ public class VPoint implements Cloneable { return Point2D.distance(x, y, other.x, other.y); } + public double distanceSq(final VPoint other) { + return Point2D.distanceSq(x, y, other.x, other.y); + } + public double distance(Point2D other) { return Point2D.distance(x, y, other.getX(), other.getY()); } diff --git a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolver.java b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolver.java index b4b5bc829c79ac10a5759deeefea235675e2da37..a6aab0ef5ae4e7376cd9220c70bc443a13818337 100644 --- a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolver.java +++ b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolver.java @@ -80,7 +80,7 @@ public interface EikonalSolver { Point gridPoint = potentialField.getNearestPointTowardsOrigin(pos); VPoint gridPointCoord = potentialField.pointToCoord(gridPoint); int incX = 1, incY = 1; - double gridPotentials[]; + double gridPotentials[] = new double[4]; if (pos.x >= potentialField.getWidth()) { incX = 0; @@ -90,12 +90,11 @@ public interface EikonalSolver { incY = 0; } - java.util.List points = new LinkedList<>(); - points.add(gridPoint); - points.add(new Point(gridPoint.x + incX, gridPoint.y)); - points.add(new Point(gridPoint.x + incX, gridPoint.y + incY)); - points.add(new Point(gridPoint.x, gridPoint.y + incY)); - gridPotentials = getGridPotentials(points, potentialField); + gridPotentials[0] = potentialField.getValue(gridPoint).potential; + gridPotentials[1] = potentialField.getValue(gridPoint.x + incX, gridPoint.y).potential; + gridPotentials[2] = potentialField.getValue(gridPoint.x + incX, gridPoint.y + incY).potential; + gridPotentials[3] = potentialField.getValue(gridPoint.x, gridPoint.y + incY).potential; + /* Interpolate the known (potential < Double.MAX_VALUE) values. */ Pair result = InterpolationUtil.bilinearInterpolationWithUnkown( diff --git a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFIM.java b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFIM.java index 2cd721631ac17319b6812eaa8e124b941c21f959..07ffdad55952e858d7365476e234a11b2a242e4d 100644 --- a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFIM.java +++ b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFIM.java @@ -28,7 +28,7 @@ import java.util.stream.Collectors; public class EikonalSolverFIM implements EikonalSolver { private CellGrid cellGrid; - private List targetShapes; + private Collection targetShapes; private List targetPoints; private static Logger logger = LogManager.getLogger(EikonalSolverFIM.class); private ITimeCostFunction timeCostFunction; @@ -40,7 +40,7 @@ public class EikonalSolverFIM implements EikonalSolver { private LinkedList activeList; public EikonalSolverFIM(final CellGrid cellGrid, - final List targetShapes, + final Collection targetShapes, final boolean isHighAccuracy, final ITimeCostFunction timeCostFunction) { this.timeCostFunction = timeCostFunction; diff --git a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFMM.java b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFMM.java index 132cb9da7e3bafc791c0c5cb6672d331287bbb2a..387a319ba22c34be241b82618705491d3f7d557a 100644 --- a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFMM.java +++ b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFMM.java @@ -2,6 +2,7 @@ package org.vadere.util.potential.calculators; import java.awt.Point; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.PriorityQueue; import java.util.stream.Collectors; @@ -29,7 +30,7 @@ public class EikonalSolverFMM implements EikonalSolver { protected CellGrid cellGrid; protected List targetPoints; - protected List targetShapes; + protected Collection targetShapes; boolean isHighAccuracy = false; /** only for logging */ @@ -40,7 +41,7 @@ public class EikonalSolverFMM implements EikonalSolver { * Initializes the FM potential calculator with a time cost function F > 0. */ public EikonalSolverFMM(CellGrid potentialField, - List targetShapes, + Collection targetShapes, boolean isHighAccuracy, ITimeCostFunction timeCostFunction) { this.cellGrid = potentialField; diff --git a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFSM.java b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFSM.java index 5c9282d632b4e88e3ceb3900e5548ca25b9f26fb..63660d8ab4a593847c0474bdee8679caee0c18a8 100644 --- a/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFSM.java +++ b/VadereUtils/src/org/vadere/util/potential/calculators/EikonalSolverFSM.java @@ -13,6 +13,7 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.stream.Collectors; @@ -36,12 +37,12 @@ public class EikonalSolverFSM implements EikonalSolver { private ITimeCostFunction timeCostFunction; private boolean isHighAccuracy; private List targetPoints; - private List targetShapes; + private Collection targetShapes; private static final double EPSILON = 0.001; public EikonalSolverFSM(final CellGrid cellGrid, - final List targetShapes, + final Collection targetShapes, final boolean isHighAccuracy, final ITimeCostFunction timeCostFunction) { this.timeCostFunction = timeCostFunction;