diff --git a/msi.gama.models/models/GAML Syntax/Data Types And Structures/Graph.gaml b/msi.gama.models/models/GAML Syntax/Data Types And Structures/Graph.gaml index 7239146215..cd5e103d76 100644 --- a/msi.gama.models/models/GAML Syntax/Data Types And Structures/Graph.gaml +++ b/msi.gama.models/models/GAML Syntax/Data Types And Structures/Graph.gaml @@ -10,11 +10,14 @@ global { int init_nb_nodes <- 1 parameter: true min: 1; int nb_nodes <- 10 parameter: true min: 1; int av_degree <- 4 parameter: true; + bool node_species_only <- false parameter:true; + bool no_species <- false parameter:true; + bool directed_graph <- false parameter:true; int x_cells <- 10; int y_cells <- 10; graph g_graph; string the_layout parameter: true init: "Circle" among: ["Circle", "Forced", "Grid"]; - string graph_generator parameter: true init: "Complete" among: ["Scall-free", "Small-world", "Complete", "Distance", "Intersection", "Grid"]; + string graph_generator parameter: true init: "Complete" among: ["Random","Scall-free", "Small-world", "Complete", "Distance", "Intersection", "Grid"]; init { write "- Using dedicated agent that extends 'graph_node' => 'species my_node parent: graph_node edge_species: my_edge' with my_edge parent: base_edge"; @@ -45,6 +48,28 @@ global { do die; } + } + + /** + * Generate a random graph based on the G(n,M) Erdős-Rényi model + * https://en.wikipedia.org/wiki/Erdős–Rényi_model + */ + action random { + write "- random graph : Erdős-Rényi = generate_random_graph(nb_nodes,nb_edges,directed,node_species,edge_species)"; + do clean; + if no_species { g_graph <- generate_random_graph(nb_nodes,nb_nodes*av_degree,directed_graph);} + else if node_species_only { g_graph <- generate_random_graph(nb_nodes,nb_nodes*av_degree,directed_graph,regular_agent_node);} + else { + g_graph <- generate_random_graph( + nb_nodes, // The number of nodes + nb_nodes*av_degree, // The number of edges + directed_graph, // directed graph + regular_agent_node, // The species of nodes + regular_agent_edge // The species of edges + ); + } + + } /* @@ -55,15 +80,19 @@ global { action scall_free { write "- Scale-free : Barabási–Albert = generate_barabasi_albert(node_species, edge_species, nb_nodes, new_edges, synchronize)"; do clean; - int new_edges_addition_per_node_introduction <- 4; - g_graph <- generate_barabasi_albert( - init_nb_nodes, // The number of nodes in the graph - new_edges_addition_per_node_introduction, // the number of edges created when a new node enter the graph - nb_nodes, // The number of nodes in the graph - true, //directed grah - regular_agent_node, // The species of nodes - regular_agent_edge // The species of edges - ); + int new_edges_addition_per_node_introduction <- 4 > init_nb_nodes ? init_nb_nodes : 4; + if no_species {g_graph <- generate_barabasi_albert(init_nb_nodes,new_edges_addition_per_node_introduction,nb_nodes,directed_graph);} + else if node_species_only {g_graph <- generate_barabasi_albert(init_nb_nodes,new_edges_addition_per_node_introduction,nb_nodes,directed_graph,regular_agent_node);} + else { + g_graph <- generate_barabasi_albert( + init_nb_nodes, // The number of nodes in the graph + new_edges_addition_per_node_introduction, // the number of edges created when a new node enter the graph + nb_nodes, // The number of nodes in the graph + directed_graph, //directed grah + regular_agent_node, // The species of nodes + regular_agent_edge // The species of edges + ); + } } /* @@ -76,14 +105,18 @@ global { do clean; float rewirering_probability <- 0.1; int fake_lattice_start_degree <- 4; // Even and more than 2 - g_graph <- generate_watts_strogatz( - nb_nodes, // The number of nodes - rewirering_probability, // The probability to rewire a node in the generation process - fake_lattice_start_degree, // The degree of node at start, before the rewirering process - false, //is directed - regular_agent_node, // The species of nodes - regular_agent_edge // The species of edges - ); + if no_species {g_graph <- generate_watts_strogatz(nb_nodes,rewirering_probability,fake_lattice_start_degree,directed_graph);} + else if node_species_only {g_graph <- generate_watts_strogatz(nb_nodes,rewirering_probability,fake_lattice_start_degree,directed_graph,regular_agent_node);} + else { + g_graph <- generate_watts_strogatz( + nb_nodes, // The number of nodes + rewirering_probability, // The probability to rewire a node in the generation process + fake_lattice_start_degree, // The degree of node at start, before the rewirering process + directed_graph, //is directed + regular_agent_node, // The species of nodes + regular_agent_edge // The species of edges + ); + } } /* @@ -92,12 +125,16 @@ global { action complete { write "- Complete = generate_complete_graph(node_species, edge_species, nb_node)"; do clean; - g_graph <- generate_complete_graph( - nb_nodes,// The number of nodes in the graph - false, //is directed - regular_agent_node, // The species of nodes - regular_agent_edge // The species of edges - ); + if no_species {g_graph <- generate_complete_graph(nb_nodes,directed_graph);} + else if node_species_only {g_graph <- generate_complete_graph(nb_nodes,directed_graph,regular_agent_node);} + else { + g_graph <- generate_complete_graph( + nb_nodes,// The number of nodes in the graph + directed_graph, //is directed + regular_agent_node, // The species of nodes + regular_agent_edge // The species of edges + ); + } } action from_nodes { @@ -347,48 +384,13 @@ experiment Graph type: gui { user_command "Create graphs" { switch graph_generator { - match "Scall-free" { - ask world { - do scall_free(); - } - - } - - match "Small-world" { - ask world { - do small_world(); - } - - } - - match "Complete" { - ask world { - do complete(); - } - - } - - match "Distance" { - ask world { - do from_nodes(); - } - - } - - match "Intersection" { - ask world { - do from_polygons(); - } - - } - - match "Grid" { - ask world { - do grid_graph(av_degree); - } - - } - + match "Random" { ask world {do random();} } + match "Scall-free" { ask world { do scall_free(); } } + match "Small-world" { ask world { do small_world(); } } + match "Complete" { ask world { do complete(); } } + match "Distance" { ask world { do from_nodes(); } } + match "Intersection" { ask world { do from_polygons(); } } + match "Grid" { ask world { do grid_graph(av_degree); } } } }