MengeCrowdSim / Menge

The source code for the Menge crowd simulation framework
Apache License 2.0
138 stars 64 forks source link

Set offset goal in cross case #106

Closed keanudicap closed 5 years ago

keanudicap commented 5 years ago

Look through all the examples, the goals have been set as AABB, mirror, point. However, I want to set the goal as a offset of the initial position. like this image

I've check the source code and found that there is a goalselectoffset file. I was wondering how I could add that into xml file?

Now, I am using AABB, however, the simulator will never stop. `

    <Goal type="AABB" id="1" min_x="-1" min_y="5" max_x="1" max_y="12" />   
</GoalSet>

<State name="WalkHorizontal" final="0" >
    <GoalSelector type="explicit" goal_set="0" goal="0"/>
    <!-- <GoalSelector type="mirror" mirror_x="1" mirror_y="0"/> -->
    <VelComponent type="goal" />`
keanudicap commented 5 years ago

sorry for the confusion of the color above. Currently, the goal above is set to be mirror like. However, it should be a constant offset of the initial position.

MengeCrowdSim commented 5 years ago

As I look at your image, I believe that there is not currently a specific goal selector/goal set that will give you what you want.

In principle, the mirror goal selector will reflect the initial positions to the same relative configuration on the left. This assumes that these two configurations are centered on the simulation world's origin.

However, I also see a vertical offset. So, what it really looks like is that the initial position is mirrored over the y-axis around some point (which may or may not be the world origin) and then offset vertically in the +y direction.

As for the question of whether the simulator stops, have you set a goal for reaching that goal and set it to final="1"?

Do I interpret that picture correctly?

keanudicap commented 5 years ago

Sorry for the confusion of the image.

Let's say we have a grid of agents, and their initial positions are listed below (I am using a XML notation here): <Generator type="rect_grid" anchor_x="-5" anchor_y="-1" offset_x="0.75" offset_y="1" count_x="8" count_y="3" />

I want the corresponding goals to be like: <Generator type="rect_grid" anchor_x="5" anchor_y="-1" offset_x="0.75" offset_y="1" count_x="8" count_y="3" />

Basically, the goal is a 10 offset of the initial position on x axis, and 0 offset on y axis.

keanudicap commented 5 years ago

as for the question of stop of the simulator: yes, the stop state is set to be final="1"

MengeCrowdSim commented 5 years ago

Sorry to make you repeat yourself -- I realized I'd focused on the picture and missed your follow-up comment about the misleading nature of the picture.

Fortunately, there is a very simple solution to your problem. There is an offset goal selector type. In looking through the examples, I realize it is not included in any of the examples which is an oversight that needs to be addressed. However, it is exactly the functionality you want.

You can learn about the parameters here. Let me know if you have any questions.

keanudicap commented 5 years ago

Thanks for the quick reply. I also noticed this 'offset' function and it could solve the problem quite straightforward. The problem is I don't know how to write the actual XML code to implement it. Thanks.

keanudicap commented 5 years ago

For example, the mirror case, <GoalSelector type="mirror" mirror_x="1" mirror_y="0"/>, the parameters and related values are not mentioned in the goalselectmirror function. How should we implement the offset goal?

MengeCrowdSim commented 5 years ago

It takes a "2D vector distribution" attribute. Essentially, you'll add a 2D vector to the initial position. What 2D vector gets added depends on the distribution. So, you can get the following:

Offset every agent by exactly <10, 0>

<GoalSelector type="offset" dist="c" x_value="10", y_value="0"/>

Create small box (with length of side = 1) centered at a location <10, 0> away from the initial position and create the goal by offset the initial position a point drawn from this box with uniform probabilities.

<GoalSelector type="offset" dist="u" min_x="9.5" max_x="10.5" min_y="-0.5" max_y="0.5"/>
MengeCrowdSim commented 5 years ago

Oops -- forget the comma in the first example.

keanudicap commented 5 years ago

Thanks for the reply. It works!

Regarding the problem of "simulator does not stop", a similar problem is, when agent reaches the goal, it doesn't immediately stops, it looks like it travels ahead a bit and then come back to the goal which results in some oscillation as shown below: image

I am using ORCA method. Is it because of some parameters in AgentProfile or somewhere I can tune to make agent stop immediately the first time it reaches the goal?

MengeCrowdSim commented 5 years ago

In its simplest configuration, there will be oscillation. This is due to a couple of reasons:

  1. There is a max_accel value that means they may not be able to stop instantaneously.
  2. If another agent is moving towards a "stopped" agent and there is an apparent risk of collision, the stopped agent will move. This is part of the ORCA model (and most pedestrian model). The stopped agent doesn't know that the oncoming agent will stop before hitting.

You could add a property setting action in the final state which increases the priority of a stopped agent. Then they'll be better able to ignore agents that haven't stopped yet.

keanudicap commented 5 years ago

Thanks. How do I set the priority in the stop state below in XML file? (there is no example) `

    <VelComponent type="goal" />
</State>`
MengeCrowdSim commented 5 years ago

You can see an example of it in the tradeshow example. In that example, when the agents reach the "Arrive" state, they temporarily set their priority to 1 (with the understanding that everyone defaults to zero).

Curiously, the action has exit_reset="0" which surprises me. I'll have to look into why that is. For your purposes, it doesn't matter since you'd be doing this in a state with no outward transitions.

MengeCrowdSim commented 5 years ago

Addendum: technically, the tradeshow doesn't set the priority, it adds 1 to the priority. If you want to set it to a specific value, you'd use type="set_property" instead of type="offset_property".

keanudicap commented 5 years ago

I've set the max_accel to be large (=10), and also set priority to the stop state to be 10. The oscillation still happens as when these parameters were not set before. image

max_accel has an effect which lower value has larger oscillation, but 5 and 10 makes no big difference. And priority has no effect to oscillation.

MengeCrowdSim commented 5 years ago

Oops. It won't affect ORCA. But if you run it with the pedvo model instead, it should make a difference. PedVO is a derivative of ORCA which includes, among other things, respect for priority.

You can set priority just to 1. Given two agents with priority a and b, the different in their priority is always clamped to a maximum value of 1. So, if you have 0 and 10 or 0 and 1, you'll get the same effect.

keanudicap commented 5 years ago

In this case, it looks like ORCA is not good at stopping at a goal immediately.

MengeCrowdSim commented 5 years ago

~Quick test -- if there's only one agent, does it stop?~

Quick test - Set the final goal to be non final (i.e., final="0") and then set it to one agent, does it stop?

keanudicap commented 5 years ago

Stopped right away.

MengeCrowdSim commented 5 years ago

And using -m pedvo in conjunction with the Action in the final state doesn't cause them to behave any differently?

keanudicap commented 5 years ago

In pedvo method, priority makes difference that in some case, the stopped agent will never be pushed by moving agents, and agents can always stop immediately once reaches the goal no matter this priority is enabled or not. However, in ORCA case. the agents always move overhead a bit, and then go back to goal in multi-agent case.

MengeCrowdSim commented 5 years ago

Yeah. ORCA doesn't understand priority. It always assumes that agents are equal and they all have to share to avoid perceived collisions. PedVO is a variant of ORCA that understands priority and reapportions the responsibility for avoiding collision based on relative priority.

I do have to admit to some surprise that the stopped agents get pushed sometimes. I'll have to look into that.

keanudicap commented 5 years ago

Thanks for your reply! I will close this issue.