I read the shape file as matrix, but when use its attributes in computations later, it seems wrong , in spite the matrix is correct in init of the model. where the sourtime & tartime are read as only same value
model ProtoType
global
{
file initdata <-file('../includes/alias519.shp');
file vor <-file('../includes/VoronoiVoronoi.shp');
matrix mydata <- 0.0 as_matrix ({5,132});
geometry shape <- envelope(vor);
int posx; int posy; int tower; int ali; int timy;
init
{
create alias from:initdata with:[posx ::int(read('pos_x')),posy ::int(read('pos_y')),
tower::int(read('mat_id')),
ali ::int(read('alias')),
timy ::int(read('time'))];
ask alias as matrix {
loop i from: 0 to:mydata.rows-1 {
// loop j from: 0 to:mydata.columns-1{
mydata[0,i]<-posx ; //write mydata[0,i] + i;
mydata[1,i]<-posy ; //write mydata[1,i] + i;
mydata[2,i]<-tower; //write mydata[2,i] + i;
mydata[3,i]<-ali ; //write mydata[3,i] + i;
mydata[4,i]<-timy ; //write mydata[4,i] + i;
// write mydata[j,i] ;
// }
// write " "+ i ;
}
}
} // init
} // global
entities
{
species alias skills:[moving] {
point source;
float sourtime<-0.0;
point targett ;
float tartime<-0.0 ;
float difftime;
float distance;
float speedy;
int posx;
int posy;
int tower;
int ali;
int timy;
init { location <- (point([ mydata[0,0],mydata[1,0] ])) ; }
reflex movement {
loop i from:0 to:mydata.rows-1 {
loop j from:0 to:mydata.columns-1 {
source <-point([mydata[0,i],mydata[1,i]]) ;
sourtime <-mydata[4,i]; // time of source
write sourtime;
targett <-point([mydata[0,i+1], mydata[0,i+1]]);
tartime <-mydata[4,i+1]; // time of targett
write tartime;
if source!=targett
{
difftime <- abs(tartime-sourtime);
distance <- source distance_to targett;
speedy <- (distance/difftime) ;
write "SourcePoint " + source ;
write "timeOfSource " + sourtime ;
write "targettPoint " + targett ;
write "timeOfTarget " + tartime ;
write "timediff " + difftime ;
write "distance " + distance ;
write "speedy " + speedy ;
write " " ;
do goto ( target:targett, on:shape ,return_path:true ,speed:speedy);
} //IF
} //loop j
} // loop i
} // reflex movement
aspect base { draw circle(5) color:rgb('red'); } } //alias species
} //entities
experiment Trajectory type: gui {
output { display city_display type:java2D
{
species alias aspect:base ;
} } }
thanks in advance
sincerely
Suhad