Anylogic - Problem by Creating Schedule and ResourcePool programmatically - schedule

Hier's the task, the agent "Machine" will be created programmatically via a excel data, and I need to create ResourcePool and Schedule for each machine programmatically which will set in a Service block.
I create two Variables and a function to create Schedule and ResourcePool like:
```
v_Workershift = new Schedule();
v_Workershift.setOwner(this);
v_Workershift.setCalendarType(true);
v_Workershift.setFirstDayOfWeek(MONDAY);
v_Workershift.setPeriod(1);
v_Workershift.setTimeUnits(DAY.toMilliseconds());
v_Workershift.setGlueIntervals(true);
v_Workershift.addInterval(1, 1, 6, 0, 0, 1, 1, 14, 0, 0, true);
v_Workershift.initialize();
//Create ResourcePool and Put the schedule"v_Workershift" into ResourcePool(v_WorkersPool)
v_WorkersPool = new ResourcePool();
v_WorkersPool.set_capacityDefinitionType(ResourcePool.CapacityDefinitionType.CAPACITY_SCHEDULE_ON_OFF);
v_WorkersPool.set_capacityScheduleOnOff(v_Workershift);
```
The function runs in the Agent "Machine" Startup and the setting in service like:
[enter image description here][1]
And there's the Problem:
there's a error by running the model:
```
Error during model startup:
root.pop_Machines[0].r_Workers:
Parameter capacityScheduleOnOff is not specified (null/empty)
```
Have i write the code correctly or i make a misstake by setting in the service block.
And could someone give me a advice, how to use the Help correctly, wenn i need to create another block programmaticly, i can only find some code in Forum, but not in Help.
Thank you very very much for your answer!
[1]: https://i.stack.imgur.com/MTEKb.png

Couple of things to note here:
The error specifically mentions root.pop_Machines[0].r_Workers - it seems that this object still doesn't have a reference to the programmatically created Schedule object. In the first code snippet provided the Schedule object is set into v_WorkersPool object.
Creating objects programmatically is generally not advisable in AnyLogic. Things such as Schedule is fine because they're more or less standalone. However a ResourcePool is fairly complex and requires a fair bit of housekeeping to make sure it is created and registered correctly. Why is it necessary to create it programmatically?
Update
A better way to do this is to:
Put the new Schedule v_Workershift into a collection called schedules
Create a population of ResourcePool blocks (call it resources). Then instead of doing v_WorkersPool = new ResourcePool(); you can use v_WorkersPool = add_resources() which will create a ResoucePool and will also take care of all the housekeeping
Have the v_WorkersPool get Schedule from that schedules collection

Related

ANSYS Mechanical Workbench Scripting - Accessing Parameters

Ansys gurus,
My project is a static structural analysis using ANSYS workbench mechanical. I have created the parametrized geometry (via Design modeler) and material property in workbench, and used ACT scripting to configure the model. However, I don't find too much information on how to access the parameters via ACT scripting.
I have confirmed that the geometric parameters are successfully created in the workbench, e.g.
ID
Paramater Name
Value
Unit
P1
diameter
50
um
The documentation LINK suggests that I can obtain parameter ID using Analysis.GetParameter(), however, the following code didn't work for me and resulted in the error as below.
Code:
STATIC_STRUCTURAL = ExtAPI.DataModel.AnalysisByName("Static Structural")
HEIGHT = STATIC_STRUCTURAL.GetParameter('height')
Error:
Property not found.
Do you have any suggestions on the cause of such error, is it because the Parameters were not imported from workbench "project schematic" to "Model", or the code I tried to retrieve the parameters was incorrect. In either cases, could you advise the correct method to access the parameters? Thank you!
hawkoli1987
If you want to access a parameter from the "project schematic" page you can create a list. If you than want to do something with this inside of mechanical, you have to send the commands to your model:
# Access the geometric parameters
allParameters = Parameters.GetAllParameters()
for parameter in allParameters:
print parameter.DisplayText
if parameter.DisplayText == 'height':
heigthParameter = parameter
# Loop over all systems in the project
for system in GetAllSystems():
# Get Model Container
model = system.GetContainer(ComponentName="Model")
# edit model component in batch mode
system.Refresh()
model.Edit(Interactive=True)
# code to be sent to ansys mechanical
cmd ='''
here goes your ACT script as string. You have to make sure, that there are no leading spaces or tabs.
'''
# send code and exit mechanical
model.SendCommand(Language='Python',Command=cmd)
model.Exit()
print "Finished script execution."

Camunda : Set Assignee to all UserTasks of the process instance

I have a requirement where I need to set assignee's to all the "user-tasks" in a process instance as soon as the instance is created, which is based on the candidate group set to the user-task.
i tries getting the user-tasks using this :
Collection<UserTask> userTasks = execution.getBpmnModelInstance().getModelElementsByType(UserTask.class);
which is correct in someway but i am not able to set the assignee's , Also, looks like this would apply to the process itself and not the process instance.
secondly , I tried getting it from the taskQuery which gives me only the next task and not all the user-tasks inside a process.
Please help !!
It does not work that way. A process flow can be simplified to "a token moves through the bpmn diagram" ... only the current position of the token is relevant. So naturally, the tasklist only gives you the current task. Not what could happen after ... which you cannot know, because if you had a gateway that continues differently based on the task outcome? So drop playing with the BPMN meta model. Focus on the runtime.
You have two choices to dynamically assign user tasks:
1.) in the modeler, instead of hard-assigning the task to "a-user", use an expression like ${taskAssignment.assignTask(task)} where "taskAssignment" is a bean that provides a String method that returns the user.
2.) add a taskListener on "create" to the task and set the assignee in the listener.
for option 2 you can use the camunda spring boot events (or the (outdated) camunda-bpm-reactor extension) to register one central component rather than adding a listener to every task.

runtimeservice.getVariables does not work because it can't find process instance id

I'm new to flowable and I'm trying to start a process instance with variables. params here is the Map of <String,Object> that I'm using to start the process. It all goes well, but if I try to get my variables back it tells me
"execution 22f42f67-5f88-11e9-9df0-d46d6dbfea92 doesn't exist"
But if I search for it in my process instances list, is there. This is what I do:
pi = runtimeService.startProcessInstanceById(processDefinitionId, params);
runtimeService.getVariables(pi.getId());
I'm stuck with this problem and I do not understand why it keeps doing this. What am I missing?
Flowable has the concept of RuntimeService and HistoryService. The first one contains only the runtime data (what is currently active) and the second one has all the data. The runtime data is a subset of the history data.
The reason why you can’t find the variables via the RuntimeService is due to the fact that the process is completed.
If you use the HistoryService then it would work as expected.

Maximo 7.6 Intergration Automation Script

I'm trying to create an Intergration Automation Script for a PUBLISHED Channel which updates a database field.
Basically for WOACTIVITY I just want a field value setting to 1 for the Work Order if the PUBLISHED channel is triggered.
Any ideas or example scripts that anyone has or can help with please? Just can't get it work.
What about using a SET processing rule on the publish channel? Processing rules are evaluated every time the channel is activated, and a SET action will let you set an attribute for the parent object to a specified value. You can read more about processing rules here.
Adding a new answer because experience, in case it helps anyone.
If you create an automation script for integration against a Publish Channel and then select External Exit or User Exit there's an implicit variable irData that has access to the MBO being worked on. You can then use that MBO as you would in any other script. Note that because you're changing a record that's integrated you'll probably want a skip rule in your publish channel that skips records with your value set or you may run into an infinite publish --> update --> publish loop.
woMbo = irData.getCurrentMbo()
woMboSet = woMbo.getThisMboSet()
woMbo.setValue("FIELD", 1)
woMboSet.save()

Sharepoint Timer Job debuggging unable to set the Breakpoint

I have a little problem. I'm trying to add a timer job following this tutorial : http://dotnetfinder.wordpress.com/2010/07/24/creatingcustomsharepointtimerjob2010/
I came to the point where my timer job is enabled and is launching every five minutes.
The problem is that it doesn't execute all the Execute method.
public override void Execute(Guid contentDbId)
{
// get a reference to the current site collection's content database
SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];
// get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database
SPList Listjob = contentDb.Sites[0].RootWeb.Lists["Liens"];
// create a new list Item, set the Title to the current day/time, and update the item
SPListItem newList = Listjob.Items.Add();
//newList["URL"] = "http://"+DateTime.Now.ToString()+".fr";
//newList.Update();
}
I attached the debugger to the OWSTIMER.EXE.
If i try to add a breakpoint at the line : SPList ListJob = ..., it's ok,
But if i try to add a new breakpoint at the next line (SPListItem newList = ...) then i have the following message :
"The following breakpoint cannot be set : ...
The CLR was unable to set the breakpoint".
Does anyone has any idea how i can make it work ?
You seem to be attaching to the correct service. See How to: Debug a Timer Job to double check your steps.
Also, as pointed out in this comment, you should restart the timer service when deploying a timer job:
mark
February 11, 2011 at 4:41 am
There is a very important step that
needs to be completed with any Timer Project. You hav to recycle the
SharPoint timer service in between deployments. Best way to do this is
to add
net stop SPTimerV4 – Pre Build
net start SPTimerV4 – Post Build
to your sharepoint project. If you do not do the above – you will be
puzzled as to why your code seems not to be up to date. The reason is
that the timer service Caches the assembly with your class. This can
cost you hours of troubleshooting, in trying to identify why your code
does not deploy.
Make sure your project configuration is in Debug mode (in Release mode compiler is setting is enabled for optimized code). Refer to this blog post