I am planning to use optplanner to optimize the server usage and if required add additional hardware on demand.
My questions is: How to auto increment one variable if system is not able to find a optimal solution after a certain fixed time?
I don't know if it would work for your specific use case but you could define a custom phase where you modify your Problem Entity.
If you need to modify a Problem Fact then I would set a time on a thread separate from the one where you called solve(). Once the timer hits 0 you can introduce a ProblemFactChange to the solver.
Related
In the Optimization Experiment
AnyLogic allows the use of the top-level agent root on the requirements expression and does not allow the use of the top-level agent root on the constraints.
Although they mention in the AnyLogic help that root can be used in the constraints expression, the help is wrong, root can not be used. Please check the answer to this question:
Error - can not use root. in the constraints expression - AnyLogic
So, in this case, to avoid the root error: use requirements or change your constraints, so they do not need access to root.
If I change my constraints, so they do not need access to root, I will need to reduce the number of parameters (decision variables) which I'm trying to avoid as much as possible till I discover that there is no way else.
However, I'm afraid that if I used the requirements instead of the constraints, this would reduce the optimization performance. As you know, the constraints reduce the search space (this is mentioned in the help, too), but they did not mention if the requirement does the same (although they mentioned that requirements help in guiding to the solution):
"A requirement can also be a restriction on a response that requires its value to fall within a specified range."
Does this mean that the requirement is exactly the same as the constraint (in terms of reducing the search space)?
According to the above-mentioned, if I used requirement instead of constraints (because it is not allowed to use root in the constraints expression), what is the effect on the performance?
so let's review the concepts here...
CONSTRAINTS
First, the constraints are evaluated before the simulation run, and this is only used to check if your parameters fulfill certain conditions:
param1 and param2 can be evaluated between 0 and 10
but the constrain can be that the sum of both has to be below 10
This is effectively to reduce the search space since there would be no point to run the model for param1=8 and param2=8 if this is not within the search space
Requirements
Requirements are evaluated AT THE END of the simulation, that's why you can use root, so you can evaluate not only the parameters, but any variable in the simulation...
For instance if a variable ends up being above 10 when the system only allows its maximum value to be 8, then the solution is not feasible.
This means that requirements and constraints are very different, but they both find unfeasible solutions...
Other options
so from the optimization experiment side you only have these 2 options: evaluate the parameters before you run the simulation, or anything in your model after the simulation is run
Of course there's another option you can use, which is to define the restrictions inside the simulation. If your model is supposed to run for 1 day, but after 1 hour, a variable in question ends up being over 10 (which is not allowed) you can just use finishSimulation() in order to end the simulation early, and your Requirements will evaluate this variable after only 1 hour reducing the time it took to run that simulation and defining the results as unfeasible.
Conclusion
Obviously if you use requirements instead of constraints, you will have to run more simulations that you want, so the speed in which the optimization will find a solution will be much lower, so you shouldn't do that and there's no reason to do that.
Of course i have no idea what you are trying to optimize, but this is how all this works, and even though the help documentation may show an error, it wouldn't make sense to use root in the constraints.
I am constructing an experiment in Anylogic, which saves data in the Parameter variation tab under a custom-class list. The model needs to perform a lot of simulations, and repetitions to optimize for Setting variables in the model itself. After x amount of iterations, I use a Python connector to run some code in finding new possible parameters for the underlaying model.
The problem I am having right now, is that around Simulation-run number 200, the memory usage is maximum (4Gb), and it proceeds to run super-slow. I have found some interesting ways to cut on memory usage, but I believe there is only one thing that could help me right now: let the system delete memory that is used for past iterations. After each iteration, the data of a simulation is stored, so I am fine with anylogic deleting the logs of the specific simulation afterwards.
Is such a thing possible? If so, how can I implement that?
Java makes use of a Garbage collector to manage memory usage and you have no control over it. How it works is that every now and then, based on some internal logic, it will collect and remove all instances of classes in memory that do not contain any active references and remove them.
Thus to reduce memory you must ensure that any instances that are no longer needed are not referenced by any of the objects currently active in your model.
To identify these you must use a Java profiler like JProfiler, or some of the free alternatives - see here for more.
This will show you exactly what classes are using up all your memory and with some deep diving you should be able to identify who is keeping reference to them.
The usecase
We got multiple changelogs stored in the database, and want to create a histogram monitoring the duration between changes.
The problem
There doesn't seem to be a way to set the start time of a Historgram.Timer, e.g we want to set it to lastUpdated given the current changelog.
Avenues of approach
1 Subclassing Histogram
Should work. However the java-lib use protected/package-private extensively, thus making it hard without copying large portions of the library.
2 Using reflection
After a Histogram.Timer is created it should be possible to use reflection to set the start field. The field is marked as private final, and thus a SecurityManager could stop us in some environments.
Ideas?
Neither of the solutions seems like the correct way to go, and I suspect that I'm overlooking a simpler solution (but could find anything at SO or google). We're using grafana to visualize our metrics, if thats at all helpful in this scenario.
You don't need to subclass Histogram, as you don't need to use Histogram.Timer only because your histogram is measuring times.
Simply call myHistogram.observe(System.now() - lastUpdated) every time you record a new change in the database.
We are working in a very complex solution using drools 6 (Fusion) and I would like your opinion about best way to read Objects created during the correlation results over time.
My first basic approach was to read Working Memory every certain time, looking for new objects and reporting them to external Service (REST).
AgendaEventListener does not seems to be the "best" approach beacuse I dont care about most of the objects being inserted in working memory, so maybe, best approach would be to inject particular "object" in some sort of service inside DRL. Is this a good approach?
You have quite a lot of options. In decreasing order of my preference:
AgendaEventListener is probably the solution requiring the smallest amount of LOC. It might be useful for other tasks as well; all you have on the negative side is one additional method call and a class test per inserted fact. Peanuts.
You can wrap the insert macro in a DRL function and collect inserted fact of class X in a global List. The problem you have here is that you'll have to pass the KieContext as a second parameter to the function call.
If the creation of a class X object is inevitably linked with its insertion into WM, you could add the registry of new objects into a static List inside class X, to be done in a factory method (or the constructor).
I'm putting your "basic approach" last because it requires much more cycles than the listener (#1) and tons of overhead for maintaining the set of X objects that have already been put to REST.
I am solving a variation on vehicle routing problem. The model worked until I implemented a change where certain vehicles and/or stops may remain unassigned because the construction filter does not allow the move due to time window considerations (late arrival not allowed).
The problem size is 2 trucks/3 stops. truck_1 has 2 stops (Stop_1 and Stop_2) assigned to it, and consequently 1 truck and 1 stop remain unassigned since truck_2 will arrive late to Stop_3.
I have the following error:
INFO o.o.c.i.c.DefaultConstructionHeuristicPhase - Construction Heuristic phase (0) ended: step total (2), time spent (141), best score (-164hard/19387soft).
java.lang.IllegalStateException: Local Search phase started with an uninitialized Solution. First initialize the Solution. For example, run a Construction Heuristic phase first.
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.phaseStarted(DefaultLocalSearchPhase.java:119)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:60)
at org.optaplanner.core.impl.solver.DefaultSolver.runPhases(DefaultSolver.java:213)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:176)
I tried to set the planning variable to null (nullable = true) but it seems it is not allowed in case of chained variables.
I am using Optaplanner 6.2.
Please help,
Thank you,
Piyush
Your construction filter may be too restrictive, it could prevent the construction heuristic from creating an initialized solution. You should remove the time window constraint from the construction filter and add it as a hard score constraint in your score calculator instead.
From the Optaplanner docs:
Instead of implementing a hard constraint, it can sometimes be built in. For example: If Lecture A should never be assigned to Room X, but it uses ValueRangeProvider on Solution, so the Solver will often try to assign it to Room X too (only to find out that it breaks a hard constraint). Use a ValueRangeProvider on the planning entity or filtered selection to define that Course A should only be assigned a Room different than X.
This can give a good performance gain in some use cases, not just because the score calculation is faster, but mainly because most optimization algorithms will spend less time evaluating unfeasible solutions. However, usually this not a good idea because there is a real risk of trading short term benefits for long term harm:
Many optimization algorithms rely on the freedom to break hard constraints when changing planning entities, to get out of local optima.
Both implementation approaches have limitations (feature compatiblity, disabling automatic performance optimizations, ...), as explained in their documentation.