I'm simulating the operation of a railroad.
I have a table with train departure time, departure location, and arrival location data. Locations are given using longitude and latitude coordinates.
I created my rail yards on the GIS map using their coordinates.
I can make the trains depart following the schedules in the table and the correct departure location.
But I can't get them to go to the right destination.
When trying to use the moveTo block you can only indicate a single destination. In my simulator, each train will go to a different yard.
How can I perform this movement using a data table and geographic coordinates?
Some pertinent remarks:
I'm not using the rail library. I'm working in the GIS space with routes determined by Anylogic itself. I didn't design or import railroads.
For this reason, I'm using the "source" and "moveTo" blocks from the process modeling library.
In the "moveTo" block I didn't find options that allow me to use the longitude and latitude data of the destination and which are stored in the data table (as I do in the "source" block).
Whenever I try to insert some code that does this, Anylogic returns saying the error:
"Exception during discrete event execution:
root:
Non-unique value in the database!"
It is better to rather use an agent-based approach for this kind of movement instead of doing it using move to blocks. It is hard to explain here but do some more tutorial examples and you will understand. You want the agents to move at a specific time and in a process flow modelling approach unless you use delay or hold blocks agents will flow from one block to the next as soon as there is space.
Here is an example of how to do it using the agent-based approach using your setup.
I have an agent called Trem with a dynamic event to move it to a specific location.
Now we populate the dynamic events with data from the database at the start of the model using the code below.
List<Tuple> rows = selectFrom(db_table)
.list();
for (Tuple row : rows) {
//What is the start time of the movement
double timeToTripBegin = dateToTime(row.get( db_table.trip_begin_time ));
//Lets create a new movement event to trigger the movement in the future
create_MoveToLocation(timeToTripBegin,
row.get( db_table.latitude_chegada ),
row.get( db_table.longitude_chegada ));
}
These events will then trigger the required movement for us when the event executes.
I've got this kind of problem with Proton CEP: i currently have a "Sequence" EPA; its input are 2 events. But these events have different granularity: let's say i have A and B events; i receive N "A" events, and M "B" events, where M << N.
So i'd like to have a rule like "if event of type A is not consumed within X seconds, remove it", otherwise i've got a long A events queue; i only need the rule to be evaluated for closest (temporally) events.
Practically, i've got a fake room temperature sensor that sends its temperature updates every 5seconds, and i've got another program that checks external weather and sends it every minute.
Any idea how to solve this situation?
Thank you very much!
I guess that in "consume" you mean arrival, so do you want to evaluate the time the A event took to get to the proton pcoressor? or the time between A events? Do you want to ensure that the A events are indeed continuous in a fix rate? "Removing" an event means to ignore it, since events are not kept anywhere, just processed. At the end, what is that you want to detect here? Like, what is the trend of room temperature compared to the outside temperature? then, emit output events accordingly?
Thanks.
all the relevant event instances are kept within the local state of a corresponding EPA.
For each EPA operand you have policies which dictates how the state is gathered and how the matching set for event derivation is built.
For example, instance selection policy which is defined per operand, and has the values of "Each", "First" and "Last" will tell you if all A instances are examined for match with B instance, or the first (in the order of arrival), or the last.
The consumption policy says what to do with the operand state once a seqence is detected - should the instances of say A which participated in sequence be removed from EPA's state ("consume" value of the policy) or should they remain.
Playing with combination of those policies should give you the behaviour you require
In developing for Fiware's Proton CEP, I came across an issue with Sequence event detection. I'll take advantage of DoSAttack example project, that comes with the software, to explain the issue.
I make two main changes to an original copy of DoSAttack:
-One is to make ExpectedCrash event have 3 more variables. This way I can log to DoSAttackTRConsumer file the 3 values that triggered it.
-Then I also change the Cardinality Policy of the Agent from Single to Unrestricted. This way the event can be triggered several times in a row, as TrafficReports come in (this may be a source to the issue).
I test this result and I find it works ok. I can see in the log that the values that trigger detection are the sequence of 3 values that arrived just before the event, after the first three events have arrived.
This, taking into account that the test beeing made on those 3 values still remains the original example test: (TR3.volume>1.50* TR2.volume AND TR2.volume>1.50 * TR1.volume).
The issue arrises if I make the test be just (TR3.volume>1.50* TR2.volume), for example, then CEP doesn't hold TR1 correctly. Now TR1 is the same as TR2, so cep loses "memory" of this value.
Going a step further, I make the test, just the condition (3>2) which is always true and should trigger a detection on any event that arrives. In this case, as events arrive, all TR1, TR2 and TR3 are the same and CEP has no memory of past values, even though the agent is of Type: Sequence.
The desired application would be for the CEP to recieve 22 readings as a sequence of input events and analyse only the 1st, 8th, 15th and 22nd values of this sequence, at each value that enters. But I find I can't make CEP remember the values correctly unless I'm testing all of them explicitly in the Condition view-box.
What would be the correct way to analyse the 1st, 8th, 15th and 22nd values that arrived, evaluating each time a new one arrives?
Here is the specificatin of DoSAttack, after altering it:
{"epn":{"events":[{"name":"TrafficReport","attributes":[{"name":"volume","type":"Integer","dimension":0}]},{"name":"ExpectedCrash","attributes":[{"name":"Cost","type":"Double","dimension":0},{"name":"TR1","type":"Integer","dimension":"0"},{"name":"TR2","type":"Integer","dimension":"0"},{"name":"TR3","type":"Integer","dimension":"0"}]}],"epas":[{"name":"IncreasingTraffic","epaType":"Sequence","context":"3MinAfterStartUp","inputEvents":[{"name":"TrafficReport","alias":"TR1","consumptionPolicy":"Consume","instanceSelectionPolicy":"First"},{"name":"TrafficReport","alias":"TR2","consumptionPolicy":"Consume","instanceSelectionPolicy":"First"},{"name":"TrafficReport","alias":"TR3","consumptionPolicy":"Consume","instanceSelectionPolicy":"First"}],"computedVariables":[],"assertion":"3>2","evaluationPolicy":"Immediate","cardinalityPolicy":"Unrestricted","internalSegmentation":[],"derivedEvents":[{"name":"ExpectedCrash","reportParticipants":false,"expressions":{"Cost":"10","TR1":"TR1.volume","TR2":"TR2.volume","TR3":"TR3.volume"}}],"derivedActions":[]}],"contexts":{"temporal":[{"name":"3MinAfterStartUp","type":"TemporalInterval","atStartup":true,"neverEnding":false,"initiators":[],"terminators":[{"terminatorType":"RelativeTime","terminationType":"Terminate","relativeTime":"180000"}]}],"segmentation":[],"composite":[]},"consumers":[{"name":"SysTemCrashConsumer","type":"File","properties":[{"name":"filename","value":"/opt/tomcat10/sample/DoSAttack_PredictedCrash.txt"},{"name":"formatter","value":"json"},{"name":"delimiter","value":";"},{"name":"tagDataSeparator","value":"="},{"name":"SendingDelay","value":"1000"}],"events":[{"name":"ExpectedCrash"}],"actions":[]},{"name":"DoSAttackTRConsumer","type":"File","properties":[{"name":"filename","value":"/opt/tomcat10/sample/DoSAttack_TrafficReport.txt"},{"name":"formatter","value":"json"},{"name":"delimiter","value":";"},{"name":"tagDataSeparator","value":"="},{"name":"SendingDelay","value":"1000"}],"events":[{"name":"TrafficReport"}],"actions":[]}],"producers":[{"name":"TrafficReportFileProducer","type":"File","properties":[{"name":"filename","value":"/opt/tomcat10/sample/DoSAttackScenarioJSON.txt"},{"name":"pollingInterval","value":"1000"},{"name":"sendingDelay","value":"1500"},{"name":"formatter","value":"json"},{"name":"delimiter","value":";"},{"name":"tagDataSeparator","value":"="}],"events":[]}],"actions":[],"name":"DoSAttack"}}
The producer file, DoSAttackScenarioJSON.txt, is still the original one, unaltered:
{"Name":"TrafficReport", "volume":"1000"}
{"Name":"TrafficReport", "volume":"1600"}
{"Name":"TrafficReport", "volume":"2500"}
If you do include more values than 3 you can see that the issue propagates.
If you need more information let me know.
Thank you
In the Sequence pattern, the engine looks for event instances that occurred in a particular order.
In Sequence (A, B, C), the engine looks for three event instances, the first one of type A, the second of type B and the third of type C, where:
(A's detection time) <= (B's detection time) AND (B's detection time) <= (C's detection time)
Usually in a Sequence pattern, either the event types are different, or there is other condition above the participants events (as in the DoSAttack example).
When you use the same event type in a sequence (e.g., Sequence(A, A, A)), then the same event instance can be used in all the three places, since it holds the detection order listed above.
In addition, if you use a "consumptionPolicy": "Consume" for a participant event, then after the event was used to detect the pattern, it will not be used for future detections of this pattern.
This is why when you have a Sequence(A, A, A) with no condition, and event instance A1 of type A arrives, it causes a pattern detection, and since it has Consume policy, it will not be kept for future detections. Later when event A2 of type A arrives, it causes another detection based on A2 alone.
Also, according to the Sequence built-in condition over the detection time, a sequence of events can be detected although other events arrived in between.
Please describe the pattern you would like to detect. Maybe you can use a Trend or Aggregate EPA instead.
I have an application that updates every 30 seconds, in which a bunch of variables and startingTime is sent which I use in charting - this is done repeatedly every 30 seconds so I have a kind of live updates. I want to re-factor this such that the first startingTime received will be used for period of one hour during which subsequent startingTime will be discarded. The whole essence is to prevent the chart being redrawn every 30s but other parameter will be used to update the chart.
How to i do this in Flex builder?
Since the dataProvider will be array collection / array based you can remove the old values on the list and add new values at the end list(basically a Queue implementation of ArrayCollection).
Now after you have done this, you will do a ArrayCollection(chart.dataprovider).refresh();
if you have the array collection binded to the chart, when you modify the arraycollection, this will be automatically reflected in the chart, so, the whole chart wont be repainted.
I'm doing some charts with analytics regarding a game. Here is the basic assumptions.
There are three possible actions a player can make.
Player can attack
Player can deffend
Player can run ( in 2 directions forwards and backwards)
Each action can happen in one of the three battlegrounds (bg a, bg b, bg c)
A player can be human or alien. Each player regarding of race can have a level.
Each player executes a particular action at a particular time.
Now i need to chart these things.
Piechart of the players race
Piechart of where the actions took place(in which of the 3 battlegrounds)
A barchart of the players level
A line chart for attacks based on time
A line chart for defends based on time
A linechart for runs( oneline for each direction of running) based on time
Each chart needs to be connected to the other ones (kondof the crossfilter flight charts are) . So for example if i click on the piechart with the player race and chose human the other charts update accordingly to reflect levels, and battlegrounds and actions pertaining just to that race.
Bottom line is i am having a hard time structuring my json input. Can any experts give me some hints?
Thank you for your time.
As I see it, the most flexible way is to build up an array of "events" (an event can be anything a player might do) with timestamps. Something like:
var playerEvents = [
{ timestamp: 1352848500, player:'human', action:'attack', location:'bg A' },
{ timestamp: 1352848600, player:'alien', action:'run', meta:'dir=left', location:'bg B' },
....
]
Once you have that, any stats you want display would involve filtering this array of events down to whatever you need for the given graphic.