gama-platform / gama.old

Main repository for developing the 1.x versions of GAMA
GNU General Public License v3.0
304 stars 99 forks source link

virtual paths computed with pedestrian skill are long and wrong with large pedestrian graphes #3793

Closed tnguyenh closed 11 months ago

tnguyenh commented 1 year ago

Describe the bug When computing virtual paths, the trajectory does not follow a short path, but it seems that some waypoints are chosen randomly on the pedestrian graph at very strange location.

The following picture shows some paths computed on a regular grid that is generated in the code below.

image

The following code create a pedestrian grid on a regular grid, the spacing between lines being 'ml'. When increasing ml (for example to 8), the grid size dicreases, and the problem is harder to notice.

model ShibuyaCrossing

global {

    geometry shape <- envelope(polygon([{0,0},{200,0},{200,121},{0,121}])) ;

    float P_shoulder_length <- 1.0 parameter: true;
    float P_proba_detour <- 0.5 parameter: true ;
    bool P_avoid_other <- true parameter: true ;
    float P_obstacle_consideration_distance <- 3.0 parameter: true ;
    float P_pedestrian_consideration_distance <- 3.0 parameter: true ;
    float P_tolerance_target <- 0.1 parameter: true;
    bool P_use_geometry_target <- true parameter: true;

    string P_model_type <- "simple" among: ["simple", "advanced"] parameter: true ; 

    float P_A_pedestrian_SFM_advanced parameter: true <- 0.16 category: "SFM advanced" ;
    float P_A_obstacles_SFM_advanced parameter: true <- 1.9 category: "SFM advanced" ;
    float P_B_pedestrian_SFM_advanced parameter: true <- 0.1 category: "SFM advanced" ;
    float P_B_obstacles_SFM_advanced parameter: true <- 1.0 category: "SFM advanced" ;
    float P_relaxion_SFM_advanced  parameter: true <- 0.5 category: "SFM advanced" ;
    float P_gama_SFM_advanced parameter: true <- 0.35 category: "SFM advanced" ;
    float P_lambda_SFM_advanced <- 0.1 parameter: true category: "SFM advanced" ;
    float P_minimal_distance_advanced <- 0.25 parameter: true category: "SFM advanced" ;

    float P_n_prime_SFM_simple parameter: true <- 3.0 category: "SFM simple" ;
    float P_n_SFM_simple parameter: true <- 2.0 category: "SFM simple" ;
    float P_lambda_SFM_simple <- 2.0 parameter: true category: "SFM simple" ;
    float P_gama_SFM_simple parameter: true <- 0.35 category: "SFM simple" ;
    float P_relaxion_SFM_simple parameter: true <- 0.54 category: "SFM simple" ;
    float P_A_pedestrian_SFM_simple parameter: true <-4.5category: "SFM simple" ;

    graph network;

    float step <- 0.1;
    int nb_people <- 8;

    geometry open_area;
    init {

        open_area <- shape;

        float ml <- 3.0;
        int i <-  -20;
        loop  while: (i+1) * ml < 1.5*shape.width{
            int j <-  -20;
            loop  while: (j+1) * ml < 1.5*shape.height{
                create pedestrian_path{
                    shape <- polyline([{i*ml,j*ml},{(i+1)*ml,j*ml}]);
                }
                create pedestrian_path{
                    shape <- polyline([{i*ml,j*ml},{i*ml,(j+1)*ml}]);
                }
                j <- j +1;
            }
            i <- i + 1;
        }

        ask pedestrian_path{
            if  !(open_area covers self.shape){
                do die;
            }
        }

        ask pedestrian_path   {
            free_space <- shape + P_shoulder_length;
        }

        network <- as_edge_graph(pedestrian_path);

        ask pedestrian_path {
            do build_intersection_areas pedestrian_graph: network;
        }

        create people number:nb_people{
            location <- any_location_in(open_area);
            obstacle_consideration_distance <-P_obstacle_consideration_distance;
            pedestrian_consideration_distance <-P_pedestrian_consideration_distance;
            shoulder_length <- P_shoulder_length;
            avoid_other <- P_avoid_other;
            proba_detour <- P_proba_detour;

            use_geometry_waypoint <- P_use_geometry_target;
            tolerance_waypoint<- P_tolerance_target;
            pedestrian_species <- [people];
            obstacle_species<-[];

            pedestrian_model <- P_model_type;

            dest <- any_location_in(open_area);
            do compute_virtual_path pedestrian_graph:network target: dest ;

            if (pedestrian_model = "simple") {
                A_pedestrians_SFM <- P_A_pedestrian_SFM_simple;
                relaxion_SFM <- P_relaxion_SFM_simple;
                gama_SFM <- P_gama_SFM_simple;
                lambda_SFM <- P_lambda_SFM_simple;
                n_prime_SFM <- P_n_prime_SFM_simple;
                n_SFM <- P_n_SFM_simple;
            } else {
                A_pedestrians_SFM <- P_A_pedestrian_SFM_advanced;
                A_obstacles_SFM <- P_A_obstacles_SFM_advanced;
                B_pedestrians_SFM <- P_B_pedestrian_SFM_advanced;
                B_obstacles_SFM <- P_B_obstacles_SFM_advanced;
                relaxion_SFM <- P_relaxion_SFM_advanced;
                gama_SFM <- P_gama_SFM_advanced;
                lambda_SFM <- P_lambda_SFM_advanced;
                minimal_distance <- P_minimal_distance_advanced;

            }
        }   

    }
}

species pedestrian_path skills: [pedestrian_road]{
    aspect default { 
        draw shape  color: #gray;
    }
    aspect free_area_aspect {
        draw free_space color: #lightpink border: #black;

    }
}

species people skills: [pedestrian]{
    rgb color <- rnd_color(255);
    float speed <- gauss(5,1.5) #km/#h min: 2 #km/#h;
    point dest;

    reflex move  {
        if (final_waypoint = nil) {
        //if norm(location - dest)<1 {
            dest <- any_location_in(open_area);
            do compute_virtual_path pedestrian_graph:network target: dest ;
        }
        do walk ;
    }   

    aspect default {
        draw square(shoulder_length/2 ) color: color;
        if true{
            draw polyline(waypoints) width: 2 color: color;
        }
    }
}

experiment ShibuyaCrossing type: gui {
    output {
        display map type: 3d axes: false background: #darkgray{
            camera 'default' location: {98.4788,143.3489,64.7132} target: {98.6933,81.909,0.0};

             species pedestrian_path aspect: default;
             species people;
        }
    }
}

Gama 1.9

ptaillandier commented 1 year ago

The problem comes from the construction of the "pedestrian path". If you change it by:

list<geometry> lines;
int num <- int(shape.width/ml);
loop k from: 0 to: num {
    lines << line([{k * world.shape.width/num, 0}, {k * world.shape.width/num, world.shape.height}]);   
}
num <- int(shape.height/ml);
loop k from: 0 to: num {
    lines << line([{0, k * world.shape.height/num, 0}, {world.shape.width, k * world.shape.height/num}]);   
}

lines <- clean_network(union(lines).geometries, 0.00, true, true);
create pedestrian_path from: lines;

It should work

chapuisk commented 1 year ago

I suspect the generation of the graph to be the source of the this issue, and in fact no need to use pedestrian operators to generate those strange path, the moving skill did the same job (black entity in the snapshot below). Still I was not able to found a workaround with the clean_network operator. Did you effectively tried @ptaillandier ?

Screen Shot 2023-04-27 at 09 22 53
ptaillandier commented 1 year ago

Yes, of course, I already answered this question on github :) . "The problem comes from the construction of the "pedestrian path". If you change it by:"

list lines; int num <- int(shape.width/ml); loop k from: 0 to: num { lines << line([{k world.shape.width/num, 0}, {k world.shape.width/num, world.shape.height}]); } num <- int(shape.height/ml); loop k from: 0 to: num { lines << line([{0, k world.shape.height/num, 0}, {world.shape.width, k world.shape.height/num}]); }

lines <- clean_network(union(lines).geometries, 0.00, true, true); create pedestrian_path from: lines;

It should work

Le jeu. 27 avr. 2023 à 14:24, Kevin Chapuis @.***> a écrit :

I suspect the generation of the graph to be the source of the this issue, and in fact no need to use pedestrian operators to generate those strange path, the moving skill did the same job (black entity in the snapshot below). Still I was not able to found a workaround with the clean_network operator. Did you effectively tried @ptaillandier https://github.com/ptaillandier ?

[image: Screen Shot 2023-04-27 at 09 22 53] https://user-images.githubusercontent.com/13599506/234789419-51305860-39fb-4976-82f6-72c60693e846.png

— Reply to this email directly, view it on GitHub https://github.com/gama-platform/gama/issues/3793#issuecomment-1524961042, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALPWHM4IGILENOLV55QSVLXDINKHANCNFSM6AAAAAAXKYSQDU . You are receiving this because you were mentioned.Message ID: @.***>

tnguyenh commented 1 year ago

Then I don't really understand where does the problem comes from. Is it due to the precision when creating the vertices of the line ? If so, would there a way for a newbie user to understand the problem and find a fix ?

hqnghi88 commented 1 year ago

@ptaillandier ơi “Comes from” or “does not come from”. Your reply on github is “edited” but still the same version image

AlexisDrogoul commented 11 months ago

Not an issue then but a bad construction of the graph if I understand clearly. I close this issue, feel free to reopen it in case it should remain opened.