doubts

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

doubts

Sohini Dhar
1.Is there a way to find whether any agent is near a particular agent?
2.how do we print a word in the context i mean on the screen in repast

sohini.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: doubts

Sohini Dhar
Hiiii,

Since I am new to repast I am trying to work out a simple program of agents moving randomly on the grid and whenever two agents meet a Hello is printed onscreen.And the whole movement stops after 1000 ticks.this is the program i have worked out but I am not getting the desired result.Kindly help me with it.

I have worked out a program and I am sending you the code because I am unable to figure out my mistake. There is no syntax error but logical error.

public class human 
{
private ContinuousSpace<Object> space;
private Grid<Object> grid;
private boolean moved;
public human(ContinuousSpace<Object> space,Grid<Object> grid)
{
this.space=space;
this.grid=grid;
}
@ScheduledMethod(start=1,interval=0.1)
public void move()
{
         
// This code is used to move the Agents move randomly in space. 
GridPoint pt = grid.getLocation(this);
if(pt.equals(grid.getLocation(this)))
{
NdPoint myPoint = space.getLocation(this);
NdPoint otherPoint = new NdPoint(pt.getX(),pt.getY());
double angle = SpatialMath.calcAngleFor2DMovement(space, myPoint, otherPoint);
space.moveByVector(this,1, angle,0);
myPoint=space.getLocation(this);
grid.moveTo (this, (int) myPoint.getX(), (int)myPoint.getY());
moved = true;
}
// This Part is used to stop the tick count at 1000.
ISchedule schedule = RunEnvironment.getInstance().getCurrentSchedule();
double currenttime = schedule.getTickCount();
if(currenttime>1000)
{
 RunEnvironment.getInstance().endRun();
}
//This is the area i am stuck. I am trying to find other objects in a particular distance.And if there is some presence of human agent there is a counter which increases.If the
value of counter is more than 2,then the screen print hello.
The value of hcount prints 0.
Context context = ContextUtils.getContext(this);
human h = (human)context.getProjection("humans"); 
        double Distance = 0.05;
int hcount=0;
GridWithin within = new GridWithin(grid,h,Distance);
for (Object obj : within.query()) 
{
if (obj instanceof human)
{
hcount++;
}
}
System.out.println(hcount);
if(hcount>=2)
{
System.out.println("Hello");
}

}
}


Regards,
Sohini



On Monday, 22 May 2017 7:30 PM, Nick Collier <[hidden email]> wrote:


Hi,

I don’t think you emails are getting through spam filters after they are approved by the repast list. Can you send it again.

NIck



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: doubts

srcnick
See my comments below.

On May 24, 2017, at 5:31 AM, Sohini Dhar <[hidden email]> wrote:

Hiiii,

Since I am new to repast I am trying to work out a simple program of agents moving randomly on the grid and whenever two agents meet a Hello is printed onscreen.And the whole movement stops after 1000 ticks.this is the program i have worked out but I am not getting the desired result.Kindly help me with it.

I have worked out a program and I am sending you the code because I am unable to figure out my mistake. There is no syntax error but logical error.

public class human 
{
private ContinuousSpace<Object> space;
private Grid<Object> grid;
private boolean moved;
public human(ContinuousSpace<Object> space,Grid<Object> grid)
{
this.space=space;
this.grid=grid;
}
@ScheduledMethod(start=1,interval=0.1)
public void move()
{



         
// This code is used to move the Agents move randomly in space. 
GridPoint pt = grid.getLocation(this);
if(pt.equals(grid.getLocation(this)))
{

This bit above will always be true. “this” refers to the current Human instance that is executing the move method. So the two pts will always be equal. 


NdPoint myPoint = space.getLocation(this);
NdPoint otherPoint = new NdPoint(pt.getX(),pt.getY());
double angle = SpatialMath.calcAngleFor2DMovement(space, myPoint, otherPoint);

Same here, the two shouldl be the same. 

space.moveByVector(this,1, angle,0);
myPoint=space.getLocation(this);
grid.moveTo (this, (int) myPoint.getX(), (int)myPoint.getY());
moved = true;
}




// This Part is used to stop the tick count at 1000.
ISchedule schedule = RunEnvironment.getInstance().getCurrentSchedule();
double currenttime = schedule.getTickCount();
if(currenttime>1000)
{
 RunEnvironment.getInstance().endRun();
}

You should can do this more correctly in your ContextBuilder with RunEnvironment.getInstance().endAt(1000). The above code will execute for every Human you make.

//This is the area i am stuck. I am trying to find other objects in a particular distance.And if there is some presence of human agent there is a counter which increases.If the
value of counter is more than 2,then the screen print hello.
The value of hcount prints 0.
Context context = ContextUtils.getContext(this);
human h = (human)context.getProjection("humans"); 

Projections are things like Grids and Continuous spaces — that’s covered in the Getting Started Guide — not agents like Humans. 

        double Distance = 0.05;
int hcount=0;
GridWithin within = new GridWithin(grid,h,Distance);

The arguments for GridWithin are the Grid, the agent around which you want to find other agents and the distance. In this case, the agent should be “this” as that refers to the Human instance that’s currently executing the code. Note that “this” is nothing to do with Repast Simphony but rather straight Java.

for (Object obj : within.query()) 
{
if (obj instanceof human)
{
hcount++;
}
}
System.out.println(hcount);
if(hcount>=2)
{
System.out.println("Hello");
}

}
}


Regards,
Sohini



On Monday, 22 May 2017 7:30 PM, Nick Collier <[hidden email]> wrote:


Hi,

I don’t think you emails are getting through spam filters after they are approved by the repast list. Can you send it again.

NIck




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest