connect points and create network

51 views
Skip to first unread message

Etienne DELAY

unread,
Jan 12, 2016, 10:13:30 AM1/12/16
to GAMA
Hi,
I have some point in a grid (c.f. fig1.png), I would like to connect them with links (c.f. network.png).

model sandboxDammAgent

global {
    /** Insert the global definitions, variables and actions here */
   
    init {
       
        ask plot_cell {
            create water_node{
                location <- myself.location;
            }
        }
    }}

grid plot_cell width: 4 height: 5 neighbours: 4 {
    float water_need <- 1.0 ;
    float water_taken <- (rnd(1000) / 1000) * 0.01 ;
    aspect base {
        draw shape color: #gray;
    }
}

species water_node {
    float water_available;
   
   
   
    aspect base {
        draw circle(1) color: #blue ;
    }
}



experiment sandboxDammAgent type: gui {
    /** Insert here the definition of the input and output of the model */
    output {
        display "grid 1" {
           
            species plot_cell aspect: base;
            species water_node aspect: base;   
        }
    }
}

All my points agents need to know how is before and how is after in the network. Some one cane give me a lead ?

best regard

Etienne
fig1.png
network.png

Patrick Taillandier

unread,
Jan 12, 2016, 11:47:13 AM1/12/16
to gama-p...@googlegroups.com
Hi,

Here a solution:

model sandboxDammAgent


global {

    graph my_graph <- graph([]);

    init {

        

        ask plot_cell {

            create water_node{

                location <- myself.location;

            }

        }

        loop i from: 0 to: 3 {

        if (i < 3) {

        water_node nx1 <- first(water_node overlapping plot_cell[i,0]);

        water_node nx2 <- first(water_node overlapping plot_cell[i+1,0]);

        add to:my_graph edge: nx1::nx2 ;

        }

        loop j from: 0 to: 3 {

        water_node ny1 <- first(water_node overlapping plot_cell[i,j]);

        water_node ny2 <- first(water_node overlapping plot_cell[i,j+1]);

        add to:my_graph edge: ny1::ny2 ;

       }

        } 

    }

}


grid plot_cell width: 4 height: 5 neighbours: 4 {

    float water_need <- 1.0 ;

    float water_taken <- (rnd(1000) / 1000) * 0.01 ;

    aspect base {

        draw shape color: #gray;

    }

}


species water_node {

    float water_available;

    

    

    

    aspect base {

        draw circle(1) color: #blue ;

    }

}




experiment sandboxDammAgent type: gui {

    output {

        display "grid 1" {

           

            species plot_cell aspect: base;

            graphics "links" {

           loop link over: my_graph.edges {

           draw link color: #white;

           }

           }

            species water_node aspect: base;    

        }

    }

}


Cheers,

Patrick

--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Etienne DELAY

unread,
Jan 13, 2016, 4:11:08 AM1/13/16
to GAMA
Hi,
Thank you Patrick, so nice !
I don't really understand how graphs object work ! There is some information about graph manipulation ? is there some primitive dedicated to graphs like neighbors ?
Can I find documentation about that ?
Etienne

Patrick Taillandier

unread,
Jan 13, 2016, 6:04:37 AM1/13/16
to gama-p...@googlegroups.com
Hi,


You have a lot of examples of what can be done with graph in the Model Library: model library/features/graphs
Otherwise, you have the list of all graph operator (among them, the neighbors of a node) here: https://code.google.com/p/gama-platform/wiki/G__OperatorsAK#Graphs-related_operators

Cheers,

Patrick

Reply all
Reply to author
Forward
0 new messages