relate each cycle with one of matrix rows

19 views
Skip to first unread message

Suhad Faisal

unread,
Sep 26, 2014, 10:09:33 AM9/26/14
to gama-p...@googlegroups.com

Hello

I want to relate my lines of data with the simulation cyle (each row of the matrix represented in one simulation cycle ) ... the code is below

thanks in advance 

global 
{   matrix<int>  init_data <- matrix<int>(csv_file('../includes/alias2191258Date.csv', ';'));
file     Voronoi<-file('../includes/VoronoiVoronoi.shp');
geometry shapeworld  <- envelope(Voronoi);
init 
{ create towervoronoi  from: Voronoi  header:true;
create aliasrep ;   } 

species aliasrep skills:[moving]
 {  int   towerid  ;
    int   posx     ;
    int   posy     ;
    int   posx1    ;  
    int   posy1    ;
    int   timings  ;
    point oldtarget;
    point newtarget;
    float distance ;
    float speedy   ;

reflex matrixreading  update:every cycle {
        loop i from: 1 to: init_data.rows-1 {
        loop j from: 0 to: init_data.columns-1 {

         if j=0 {towerid <- init_data[j,i]; write towerid             ; }
 if j=1 {posx    <- init_data[j,i]; posx1  <- init_data[j,i+1]; }
         if j=2 {posy    <- init_data[j,i]; posy1  <- init_data[j,i+1]; }
         if j=7 {timings <- init_data[j,i]; write "time  "+ timings   ; }
         
                                             }
        oldtarget <-point([posx, posy]) ;  write "OLD    "+ oldtarget ;
        newtarget <-point([posx1,posy1]); write "NEW    " +newtarget ; 
                 
         if oldtarget!=newtarget    
      { distance  <- oldtarget distance_to newtarget;
       speedy    <-distance/timings ;
       write "Dis    " + distance ;
       write "Speed  " + speedy   ; 
      }
     do  goto   target: newtarget  return_path:true speed:speedy ; 
    } }  //closing i loop & reflex matrixreading
aspect basealias{ 
             draw circle(1)     color:rgb('red')          ;
                 draw '  '+ towerid color:rgb('black') size:3 ; 
 }   }  //closing aspect & species
species towervoronoi { 
aspect towericon { draw shape color:rgb(52,52,52); 
               draw rectangle(1,1500) color:rgb('black') at:location;
}   }

}
experiment Trajectory type: gui  {
    output { display  city_display type:java2D
  { image    'background'     file:'../includes/DivisionVoronoi.jpg';
species  towervoronoi   aspect: towericon     transparency: 0.7;
species  aliasrep       aspect: basealias;
   }  }  } 

cheers
Suhad

Reply all
Reply to author
Forward
0 new messages