gama-platform / gama

Main repository for developing the 2024+ versions of GAMA
https://gama-platform.org
GNU General Public License v3.0
12 stars 5 forks source link

[Graph] neighbors_of and neighbors_at raised wrong casting exception with topology graph #138

Closed chapuisk closed 1 month ago

chapuisk commented 3 months ago

Describe the bug Trying to get neighbors at distance n of an agent within a graph raises an exception.

To Reproduce Steps to reproduce the behavior: Copy past the model below

global {

    graph<a,unknown> g;

    init {

    create a number:10;
        g <- graph([]);

        loop agt over: a { add node(agt) to: g; }
        loop i from: 0 to: length(g.vertices) - 2 {
            loop j from: i+1 to: length(g.vertices)-1 {
                add edge(g.vertices[i],g.vertices[j]) to: g;
            }
        }

        a caller <- any(a);
        ask g neighbors_of caller {write self;}
    ask neighbors_of (topology(g), caller, 1) {write self;}

    }
}

species a { }

experiment xp { }
  1. Execute the model
  2. See error

Expected behavior return same results with both neighbors_of calls! Note that the same happens with the neighbors_at operator using graph topology

Desktop (please complete the following information):

ptaillandier commented 3 months ago

I don't know if it's really a bug or just a normal result. The problem comes from the fact that g is not a spatialized graph, so we can't use spatial operators on it and so asking for g's topology returns a non-spatial topology (not with geometries) which doesn't work with neighbors_of(topology...). On the other hand, the neighbors_of graph operator works on all graph types.

You can easily correct the error in the model by changing: g <-graph([]); p g <- spatial_graph([]);

The question is how to improve this? With a more explicit error message? Something else?

chapuisk commented 3 months ago

@ptaillandier now i understand. Imho, spatial graph should be the default, i.e. don't have to go through an operator to specify it. That means we could have an operator to "unspatialize" a graph, but is it usefull anyway? Because non spatial graph means non agent graph... May be it is necessary for performance issue, more or less like grid and fields. Otherwise i dont see the point to having both.

ptaillandier commented 3 months ago

Non-spatial graphs are interesting when you just need a graph structure for example for argumentation graphs for which nodes represent arguments. The notion of "location" does not make sense in this case.

Le mar. 2 avr. 2024 à 14:12, Kevin Chapuis @.***> a écrit :

@ptaillandier https://github.com/ptaillandier now i understand. Imho, spatial graph should be the default, i.e. don't have to go through an operator to specify it. That means we could have an operator to "unspatialize" a graph, but is it usefull anyway? Because non spatial graph means non agent graph... May be it is necessary for performance issue, more or less like grid and fields. Otherwise i dont see the point to having both.

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