Add_people() function in Agent population and SD housing example of anylogic - anylogic

I have tried to use add_people() in an event during running the Agent population and SD housing example of anylogic, in order to add more agents to the model during the simulation but I face this error.
How can I solve this problem?
[Exception during discrete event execution:
-1
java.lang.ArrayIndexOutOfBoundsException: -1
at com.anylogic.engine.Dimension.getIndexPosition(Unknown Source)
at com.anylogic.engine.HyperArray.getPosOf(Unknown Source)
at com.anylogic.engine.HyperArray.get(Unknown Source)
at agent_population_and_sd_housing.Person.makeDecision(Person.java:428)
at agent_population_and_sd_housing.Person.executeActionOf(Person.java:408)
at com.anylogic.engine.EventRate.execute(Unknown Source)
at com.anylogic.engine.Engine.m(Unknown Source)
at com.anylogic.engine.Engine.jd(Unknown Source)
at com.anylogic.engine.Engine.h(Unknown Source)
at com.anylogic.engine.Engine$g.run(Unknown Source)]

This is because in the Person agent, there is a variable called district that has an initial value of -1... (meaning that it doesn't have an assigned district).
To fix this, you need to assign a district to the new person you are creating:
This code:
Person p=add_people();
p.district=3;
Will create a person and assign a district equals to 3... I chose 3 arbitrarily and you have to figure out what district you want for that person in particular yourself.

Related

anyLogic root.?<PMLSettings>.i: Trying to schedule an event in the past. Negative timeout: -0.2926010883311392

when I run my model, sometimes the follow error occurred, it seems "Hold" process its unblock() methods
cause this.
Exception during discrete event execution:
root.?<PMLSettings>.i: Trying to schedule an event in the past. Negative timeout: -0.2926010883311392
java.lang.RuntimeException: root.?<PMLSettings>.i: Trying to schedule an event in the past. Negative timeout: -0.2926010883311392
at com.anylogic.engine.Engine.error(Unknown Source)
at com.anylogic.engine.EventOriginator.m(Unknown Source)
at com.anylogic.engine.DynamicEvent.<init>(Unknown Source)
at com.anylogic.engine.LibraryEventHandler$i.<init>(Unknown Source)
at com.anylogic.engine.LibraryEventHandler.m(Unknown Source)
at com.anylogic.engine.LibraryEventHandler.m(Unknown Source)
at com.anylogic.engine.LibraryEventHandler.c(Unknown Source)
at com.anylogic.engine.LibraryEventHandler.m(Unknown Source)
at com.anylogic.engine.LibraryEventHandler.addEvent(Unknown Source)
at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal$a.<init>(Unknown Source)
at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.notifyReady(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBuffer.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBuffer.take(Unknown Source)
at com.anylogic.libraries.processmodeling.Delay.stopDelay(Unknown Source)
at com.anylogic.libraries.processmodeling.MoveTo$a.onArrival(Unknown Source)
at com.anylogic.engine.l.a(Unknown Source)
at com.anylogic.engine.ca.m(Unknown Source)
at com.anylogic.engine.ca$m.execute(Unknown Source)
at com.anylogic.engine.Engine.f(Unknown Source)
at com.anylogic.engine.Engine.fn(Unknown Source)
at com.anylogic.engine.Engine$i.run(Unknown Source)
i try to set "Delay" sleep more times,but not helpanylogic
This is pretty simple and the error is telling you what you are doing wrong... You have something in your model (and it's not possible to see what it is through the error) that has a negative timeout
AnyLogic has many events happening all the time (events, dynamic events, transitions, etc) and each one of them requires a defined amount of time to be triggered.
We often use variables or functions to calculate what that timeout should be, and in your case, the calculation of that time turns out to be a negative value. You need to discover that on your own though since you don't give us enough information to tell you what it is.

AnyLogic: Unreachable Target in Agent-Based-Simulation

I am building an airport model with passengers spawning, shopping/eating and departing.
Most passengers rush to their GateArea (Polygonal Node) and wait there until they feel it is appropriate to engage in discretionary activities. When they think about leaving the GateArea they generate a "Eat"- or "Shop"- Goal" and are transferred into a PedGoTo-Block that is linked to the according shop. At this point I sometimes get the error:
java.lang.RuntimeException: root.pGT_F_B2.pedGoToTarget:
Unreachable target: (599.37, 398.48) on level 'name: level' for pedestrian 'id: 46' located at: (467.15, 222.68) on level 'name: level'!
at com.anylogic.engine.Engine.error(Unknown Source)
at com.anylogic.engine.Agent.error(Unknown Source)
at com.anylogic.engine.Utilities.error(Unknown Source)
at com.anylogic.libraries.pedestrian.PedBlock_xjal.error(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.d(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.c(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.g(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.f(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.d(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.a(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal.a(Unknown Source)
at com.anylogic.libraries.pedestrian.PedGoTo_xjal$1.onEnter(Unknown Source)
at com.anylogic.libraries.processmodeling.Delay.b(Unknown Source)
at com.anylogic.libraries.processmodeling.Delay.b(Unknown Source)
at com.anylogic.libraries.processmodeling.Delay$9.onEnter(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.b(Unknown Source)
at com.anylogic.libraries.processmodeling.InPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.InPort.receiveImmediately(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.PlainTransfer$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.forwardReadyEntityNotification(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock$2.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock$2.action(Unknown Source)
at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal$a.execute(Unknown Source)
at com.anylogic.engine.LibraryEventHandler$b.execute(Unknown Source)
at com.anylogic.engine.Engine.c(Unknown Source)
at com.anylogic.engine.Engine.fi(Unknown Source)
at com.anylogic.engine.Engine.n(Unknown Source)
at com.anylogic.engine.Engine$b.run(Unknown Source)
As you can see in the picture, neither the gate nor the shop are blocked by some static obstacles. The problem seem to be between the passengers, since they seem to block each other. I tried using less passengers per flight, which delayed the problem (or even solved it when I used very small numbers). However, the passenger numbers causing the problem are realistic (around 100) and so is the sizing of the GateArea.
Is there a way to tell passengers to "push" other agents to create a pathway or another way to solve the problem without lowering the numbers (and therefore compromising the simulation quality)?
Crowded Gate with error indication
PS. This is my first question on StackOverflow, so feel free to advise me on how to improve the question. I am hoping to get enough reputation to upvote the answers at other AnyLogic questions, since they helped more than once to overcome some deadlocks.
Assuming that there really aren't any obstacles other than other pedestrians, then the parameter that can help improve your situation is the diameter of the pedestrian. Reducing it means that pedestrians can get closer to each other.
You can also change the diameter dynamically at any point of your simulation using ped.setDiameter( x ). So for example, you can set it to 0 at that specific point in time until the pedestrian leaves that area and change it back to 0.5.
Following the discussion in the comments, it appeared that the issue was not the diameter. Nonetheless, I am keeping it above as it might be the issue for someone facing a similar problem.
The real issue was that the modeler asking the question was making the agent leave the pedestrian flow chart using remove(agent). Once the agent is sent back to the flowchart using an Enter block, AnyLogic no longer recognizes that agent as a pedestrian present in the pedestrian network.
As such, instead of using Enter block, pedEnter should be used. The latter requires as input the location of the pedestrian's appearance. Since in your case the pedestrian is not really moving, just leaving the flowchart for modeling purposes, you can specify the location as the agent's current location as shown below.

capacity parameter must be greater than 0

I am trying to create an optimization experiment but when trying to run this error appears:
root.queue1:
capacity parameter must be greater than 0
java.lang.RuntimeException: root.queue1:
capacity parameter must be greater than 0
at com.anylogic.engine.Engine.error(Unknown Source)
at com.anylogic.engine.Agent.error(Unknown Source)
at com.anylogic.engine.Utilities.error(Unknown Source)
at com.anylogic.libraries.processmodeling.Queue.onCreate(Unknown Source)
at com.anylogic.engine.Agent.n(Unknown Source)
at com.anylogic.engine.Agent.n(Unknown Source)
at com.anylogic.engine.Agent.create(Unknown Source)
at com.anylogic.engine.Engine.start(Unknown Source)
at com.anylogic.engine.ExperimentOptimization$m.m(Unknown Source)
at com.anylogic.engine.j$c.run(Unknown Source)
the problem is that capacity of queue1 is greater than 0 by default, so i dont understand where i did a mistake =(
concept is i need to Implement an optimization experiment to determine the optimal number of fuel dispensers, at which the fueling profit during 10 days will be maximum.
model look like this:
You define the capacity wrong. Simply write queue_95 into the field, not queue1.capacity=queue_95.
Also, make sure that queue_95 never is 0 or lower, obviously. (Whatever queue_95 even is)

Best practices for PartitionedSearch with chained planning variables?

I've been experimenting with a modified version of TWVSP, using chained planning variables and anchors. Similar approach as the TWVSP example with Standstill.
It looks like this:
Vehicle1 (AnchorShadowVarialbe) - Trip1_1 - Trip1_2 - ... - Trip1_k1
...
VehicleM (Anchor) - TripM_1 - TripM_2 - ... - TripM_kM
Trips are assigned to vehicles. Each trip has a start/end timestamp. One vehicle cannot service 2 trips that are overlapping.
To speed up the solver, I started splitting the search space into partitions with a SolutionPartitioner implementation, since the trips could be grouped into clusters based on their timeframes. The goal is to get trip-vehicle assignments for the clusters, but I have one vehicle fleet.
First issue, that I can't use the same vehicle objects, because the solver will fail with IllegalStateException - which is fine, I clone the list of vehicles for each partition and assign to trips to those cloned objects.
Then, I catch the phaseEnded event where phaseScope is an instance of PartitionedSearchPhaseScope (ie partition search ended event) and reassign the trips to the original vehicle objects (making sure that pointers are pointing to the same objects in each direction (similar to previousStandstill, nextVisit form the example)), as well as manually fix the chains, so cluster-chains are anchored only to the original vehicle, and they are chained together:
vehicleX - (partition0.trip(0)) - ... - (partition(i-1).trip(last)) - (partition(i).trip(0)) - ...
Then I update the solution in the solution scope:
partitionPhaseScope.getSolverScope().setBestSolution(mergedSolution);
I want to do a local search after the partitioned one, as it's advised in the docs, but get an error:
Caused by: java.lang.IllegalStateException: The move thread with moveThreadIndex (65) has thrown an exception. Relayed here in the parent thread.
at org.optaplanner.core.impl.heuristic.thread.OrderByMoveIndexBlockingQueue.take(OrderByMoveIndexBlockingQueue.java:147)
at org.optaplanner.core.impl.localsearch.decider.MultiThreadedLocalSearchDecider.forageResult(MultiThreadedLocalSearchDecider.java:188)
at org.optaplanner.core.impl.localsearch.decider.MultiThreadedLocalSearchDecider.decideNextStep(MultiThreadedLocalSearchDecider.java:159)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:71)
at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:99)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:189)
at com.mynamespace.planner.v4.rest.ScheduleResource.startSolving(ScheduleResource.java:221)
at com.mynamespace.planner.v4.rest.ScheduleResource.solve(ScheduleResource.java:112)
at com.mynamespace.planner.v4.rest.ScheduleResource_ClientProxy.solve(ScheduleResource_ClientProxy.zig:156)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:638)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:504)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:454)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:456)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:417)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:391)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:68)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:488)
... 49 more
Caused by: java.lang.NullPointerException
at org.drools.core.common.NamedEntryPoint.update(NamedEntryPoint.java:353)
at org.drools.core.common.NamedEntryPoint.update(NamedEntryPoint.java:338)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:1587)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:1559)
at org.optaplanner.core.impl.score.stream.drools.DroolsConstraintSession.update(DroolsConstraintSession.java:47)
at org.optaplanner.core.impl.score.director.stream.ConstraintStreamScoreDirector.afterVariableChanged(ConstraintStreamScoreDirector.java:141)
at org.optaplanner.core.impl.domain.variable.inverserelation.SingletonInverseVariableListener.retract(SingletonInverseVariableListener.java:96)
at org.optaplanner.core.impl.domain.variable.inverserelation.SingletonInverseVariableListener.beforeVariableChanged(SingletonInverseVariableListener.java:46)
at org.optaplanner.core.impl.domain.variable.listener.support.VariableListenerSupport.beforeVariableChanged(VariableListenerSupport.java:174)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.beforeVariableChanged(AbstractScoreDirector.java:433)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.changeVariableFacade(AbstractScoreDirector.java:446)
at org.optaplanner.core.impl.heuristic.selector.move.generic.chained.ChainedChangeMove.doMoveOnGenuineVariables(ChainedChangeMove.java:74)
at org.optaplanner.core.impl.heuristic.move.AbstractMove.doMove(AbstractMove.java:36)
at org.optaplanner.core.impl.heuristic.move.AbstractMove.doMove(AbstractMove.java:31)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.doAndProcessMove(AbstractScoreDirector.java:178)
at org.optaplanner.core.impl.heuristic.thread.MoveThreadRunner.run(MoveThreadRunner.java:146)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
Any ideas what's missing?
Is there any docs on how to do PartitionedSearch with chained planning variables?
Thanks.
The FactHandle is probably null, so at the very least, the error message should be improved: https://issues.redhat.com/browse/PLANNER-2222
As for the actual bug, your Partitioned probably creates a partition that doesn't have that fact in it's #ProblemFactCollectionProperty or #PlanningEntityCollectionProperty, but does have it in a chained entity's trailing chain (= think variable listeners for arrival time etc that "update" it).

Processing P2D in eclipse noSuchMethodError glVertexAttribPointer(IIIZILjava/nio/Buffer;)

I'm trying to run a processing sketch in eclipse. I've been doing this for quite a while, but have only recently updated to 2.1.
The sketch runs fine when running the software mode. But when I try to use the P2D mode I get the error below.
I have included all the jogl jars from the processing folder. I'm not sure if I should add native libraries though, I can't seem to find them.
Exception in thread "Animation Thread" java.lang.RuntimeException: java.lang.NoSuchMethodError: javax.media.opengl.GL2ES2.glVertexAttribPointer(IIIZILjava/nio/Buffer;)V
at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
at javax.media.opengl.Threading.invoke(Threading.java:191)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:492)
at processing.opengl.PGL.requestDraw(PGL.java:1155)
at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1602)
at processing.core.PApplet.run(PApplet.java:2141)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodError: javax.media.opengl.GL2ES2.glVertexAttribPointer(IIIZILjava/nio/Buffer;)V
at processing.opengl.PGL.vertexAttribPointer(PGL.java:3318)
at processing.opengl.PGL.drawTexture2D(PGL.java:1594)
at processing.opengl.PGL.drawTexture(PGL.java:1507)
at processing.opengl.PGL.endDraw(PGL.java:1110)
at processing.opengl.PGraphicsOpenGL.endOnscreenDraw(PGraphicsOpenGL.java:5974)
at processing.opengl.PGraphicsOpenGL.endDraw(PGraphicsOpenGL.java:1681)
at processing.core.PApplet.handleDraw(PApplet.java:2290)
at processing.opengl.PGL$PGLListener.display(PGL.java:2643)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:590)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:574)
at javax.media.opengl.awt.GLCanvas$9.run(GLCanvas.java:1218)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1036)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:911)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1229)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I can confirm that the GLES20 function glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, Buffer buf) is not available within JOGL's GL2ES2 API.
It has instead been replaced with glVertexAttribPointer(int indx, int size, int type, boolean normalized, int stride, long ptr_buffer_offset).
The high level methodology associated with it's usage is as follows, after compiling and linking your attribute-dependent shaders within a program:
Load your vertices into a Vertex Buffer Object (VBO).
Instantiate a corresponding Index Buffer Object, used to inform OpenGL
of the order in which the VBO vertices need to be iterated through.
Bind to the VBO.
Define your call to glVertexAttribPointer, which informs OpenGL of the structure of your vertex data.
Enable the attribute using glEnableVertexAttribArray.
Bind to your Index Buffer Object.
Use glDrawElements to draw your VBO vertices in the order specified by your IBO.
Unbind from the IBO.
Disable the attribute.
Unbind from your VBO.
ptr_buffer_offset then references the internal offset within that bound buffer, therefore to read from the beginning of the buffer you can just specify 0L. The same goes for for your call to glDrawElements.