Re: [gama (2279)] Using cluster method

43 views
Skip to first unread message

Patrick Taillandier

unread,
Apr 30, 2014, 3:43:17 AM4/30/14
to gama-p...@googlegroups.com
Hi,

Just to be sure, which version of GAMA are you using?

If you are using GAMA 1.6, here a simple example (simple clustering by distance, with a max distance of 20m) : 

model town

global{

       file shape_file_buildings <- file('../includes/building.shp');

       file shape_file_roads <- file('../includes/road.shp');

       int nb_people <- 100;

       geometry shape <- envelope(shape_file_roads);

       init{

               create building from: shape_file_buildings with: [type::string(read ('NATURE'))] {      

                       if type='Industrial' {

                               color <- rgb('blue');

                               datasize <- 1000;

                               recurence <-1000;

                       }

                       else if type='Residential'{

                               color <- rgb('red');

                               datasize <- 1000;

                               recurence <-1000;

                       }

               }

               list<building> residential_buildings <- building where (each.type='Residential');

               list<building>  industrial_buildings <- building where (each.type='Industrial');

               create road from: shape_file_roads ;

               create home number: nb_people {

                        living_place <- one_of(residential_buildings) ;

                        location <- any_location_in (living_place);  

               }
               list<list<building>> clusters <- simple_clustering_by_distance(building, 20);
               
               loop cluster over: clusters {
                rgb rnd_color <- rgb(rnd(255),rnd(255),rnd(255));
                ask cluster as: building {
                color <- rnd_color;
                }
               }

       }

}

species building

{

       rgb color;

       string type;

       int datasize;

       int recurence;

       aspect geometry {

               draw shape color: color;

       }

}

species road

{

       aspect geometry {

               draw shape color: rgb("black");

       }

}

species home

{

       building living_place;

       point location;

}

experiment town type: gui{

       output{

               display first_map {

                       species building aspect:geometry;

                       species road aspect:geometry;

               }

       }

}

Cheers,

Patrick


2014-04-30 8:40 GMT+02:00 Steffel Fenix <steffe...@gmail.com>:
Hello,

I'm new in GAMA and i'm trying to use the clustering algorithms, but I can't figure out how to use it I've build a simple example of a town and I want to aggregate buildings into cluster.

This is my sample code:

model town

global{

       file shape_file_buildings <- file('../includes/building.shp');

       file shape_file_roads <- file('../includes/road.shp');

       int nb_people <- 100;

       geometry shape <- envelope(shape_file_roads);

       init{

               create building from: shape_file_buildings with: [type::string(read ('NATURE'))] {      

                       if type='Industrial' {

                               color <- rgb('blue');

                               datasize <- 1000;

                               recurence <-1000;

                       }

                       else if type='Residential'{

                               color <- rgb('red');

                               datasize <- 1000;

                               recurence <-1000;

                       }

               }

               list<building> residential_buildings <- building where (each.type='Residential');

               list<building>  industrial_buildings <- building where (each.type='Industrial');

               create road from: shape_file_roads ;

               create species: home number: nb_people {

                        living_place <- one_of(residential_buildings) ;

                        location <- any_location_in (living_place);  

               }

       }

}

species building

{

       rgb color;

       string type;

       int datasize;

       int recurence;

       aspect geometry {

               draw shape color: rgb(color);

       }

}

species road

{

       aspect geometry {

               draw shape color: rgb("black");

       }

}

species home

{

       building living_place;

       point location;

}

experiment town type: gui{

       output{

               display first_map {

                       species building aspect:geometry;

                       species road aspect:geometry;

               }

       }

}


Thanks/Merci

--
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 http://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

Patrick Taillandier

unread,
Apr 30, 2014, 3:55:48 AM4/30/14
to gama-p...@googlegroups.com
From myself, I just wrote it ;) . 
However, I will add an example model concerning the clustering in the model library of GAMA 1.6.1.

Patrick


2014-04-30 9:53 GMT+02:00 Steffel Fenix <steffe...@gmail.com>:
Where does this example come from?

Patrick Taillandier

unread,
Apr 30, 2014, 4:59:47 AM4/30/14
to gama-p...@googlegroups.com
I am sure of what you want to do, but surely.

Patrick


2014-04-30 10:34 GMT+02:00 Steffel Fenix <steffe...@gmail.com>:
Just one more thing, is it possible during the run time to add moving cars to the closest cluster and make them change when the move?
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages