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

Model Graph.gaml often throws Illegal Argument error when calculating shortest path #148

Closed lesquoyb closed 3 months ago

lesquoyb commented 3 months ago

Describe the bug When clicking on the button "Path with Graph" in the model Graph.gaml from Models Library There's often an illegal argument exception raised by gama. It sometimes takes a few tries but it is very frequent.

Here is the message I have in the user interface:

2 occurrences in 2 agents at cycle 15: Java error: illegal argument
in Graph0
in map<int, geometry> mfb <- map<int, geometry>(max_flow_between(g_graph,node1,node2));
IllegalArgumentException: source is equal to sink
org.jgrapht.alg.flow.EdmondsKarpMFImpl.calculateMaximumFlow(EdmondsKarpMFImpl.java:164)
org.jgrapht.alg.flow.EdmondsKarpMFImpl.getMaximumFlow(EdmondsKarpMFImpl.java:135)
gama.gaml.operators.Graphs.maxFlowBetween(Graphs.java:2453)
gaml.additions.core.GamlAdditions.lambda$624(GamlAdditions.java:677)
gama.gaml.expressions.operators.AbstractNAryOperator._value(AbstractNAryOperator.java:388)
gama.gaml.expressions.AbstractExpression.value(AbstractExpression.java:87)
gama.gaml.expressions.operators.BinaryOperator._value(BinaryOperator.java:148)
when applying the max_flow_between operator on [graph { 
vertices (10): [0,1,2,3,4,5,6,7,8,9,]
edges (45): [
regular_agent_edge0 (0 -> 1),
regular_agent_edge1 (0 -> 2),
regular_agent_edge2 (0 -> 3),
regular_agent_edge3 (0 -> 4),
regular_agent_edge4 (0 -> 5),
regular_agent_edge5 (0 -> 6),
regular_agent_edge6 (0 -> 7),
regular_agent_edge7 (0 -> 8),
regular_agent_edge8 (0 -> 9),
regular_agent_edge9 (1 -> 2),
regular_agent_edge10    (1 -> 3),
regular_agent_edge11    (1 -> 4),
regular_agent_edge12    (1 -> 5),
regular_agent_edge13    (1 -> 6),
regular_agent_edge14    (1 -> 7),
regular_agent_edge15    (1 -> 8),
regular_agent_edge16    (1 -> 9),
regular_agent_edge17    (2 -> 3),
regular_agent_edge18    (2 -> 4),
regular_agent_edge19    (2 -> 5),
regular_agent_edge20    (2 -> 6),
regular_agent_edge21    (2 -> 7),
regular_agent_edge22    (2 -> 8),
regular_agent_edge23    (2 -> 9),
regular_agent_edge24    (3 -> 4),
regular_agent_edge25    (3 -> 5),
regular_agent_edge26    (3 -> 6),
regular_agent_edge27    (3 -> 7),
regular_agent_edge28    (3 -> 8),
regular_agent_edge29    (3 -> 9),
regular_agent_edge30    (4 -> 5),
regular_agent_edge31    (4 -> 6),
regular_agent_edge32    (4 -> 7),
regular_agent_edge33    (4 -> 8),
regular_agent_edge34    (4 -> 9),
regular_agent_edge35    (5 -> 6),
regular_agent_edge36    (5 -> 7),
regular_agent_edge37    (5 -> 8),
regular_agent_edge38    (5 -> 9),
regular_agent_edge39    (6 -> 7),
regular_agent_edge40    (6 -> 8),
regular_agent_edge41    (6 -> 9),
regular_agent_edge42    (7 -> 8),
regular_agent_edge43    (7 -> 9),
regular_agent_edge44    (8 -> 9),
]
}, 9, 9]
in map<int, geometry> mfb <- map<int, geometry>(max_flow_between(g_graph,node1,node2));
in action path_finding_graph  {
    write '
    ====================' ;
    write 'GRAPH PATH OPERATORS
    ' ;
    write 'The matrix of predecessor in all shortest path: ' ;
    matrix<int> sp <- all_pairs_shortest_path(g_graph);
    write first(10,sp) ;
    g_graph <- load_shortest_paths(g_graph,sp);
    geometry node1 <- any(g_graph.vertices);
    geometry node2 <- any(g_graph.vertices);
    map<int, geometry> mfb <- map<int, geometry>(max_flow_between(g_graph,node1,node2));
    write 'Find a path between two nodes: \'graph path_between (node1, node2)\'' ;
    the_path <- path_between(g_graph,node1,node2);
}

in do path_finding_graph ;
in ask world  {
    do path_finding_graph ;
}

in ask world  {
    do path_finding_graph ;
}

in user_command 'Path with graph'  {
    ask world  {
        do path_finding_graph ;
    }

}

in agents Simulation 0, Graph0

It may be related to some threading issue as it's easier to get it when double clicking (or probably more) on the button