Nullable chained planning variable in Optaplanner - optaplanner

So I am looking at modelling an overconstrained routing problem, where not all tasks have to be picked up in that specific planning problem. Rather the objective will be to maximise the tasks picked up in that planning problem.
I was thinking this should be easy to achieve by allowing the planning variable to be nullable, but it seems that Optaplanner does not allow this on chained planning variables.
So the workaround I am thinking about would be to devise a Dummy/Ghost vehicle for which the objective be to rather minimise the tasks assigned to this vehicle. This approach seems to echo what has been said here.
Alternatively, I think I can put the value null in the valueRangeProvider but I am not sure if this would work as intended.
Is this a reasonable approach, or are there caveats using this approach ?

null in ValueRangeProvider doesn't work.
The Dummy workaround is very, very common - I did it a few times myself (including for the RH summit demo). But once PLANNER-226 is fixed, we can get rid of that dummy workaround.

Related

Does shadow variable help optaplanner to make a better initial solution?

I’m using Optaplanner to make a schedule and it works quite good.
After reading the documentation I have realised that I should use at least 1 (or more) shadow variables since my drool-file is calling methods that does a lot of calculations based on the value of the planningVariable.
I spent a couple of hours rewriting my code to have a shadow variable, but then I notice that the initial solution was really bad (compared to not having shadow variables) and I had to wait severals of minutes just to get an OK result. Is this normal? It did not look like the initial solution used the shadow variable at all.
The question is very generic, and so my answer will be, too.
Sometimes you can simplify the problem by introducing shadow variables or other forms of caching. If you find the right balance, you can indeed speed up the Drools calculation and - as a result - get to the same solution in a shorter amount of time. And therefore, reach better solutions in the same amount of time.
That said, introducing shadow variables shouldn't really change your scores - only how quickly they're calculated. If you're seeing different scores for the same #PlanningSolution, you have in fact changed your problem and the relative performance is no longer comparable.
Also, you may want to check out environment modes to make sure you haven't inadvertently introduced score corruptions into your problem.

Implementing a planning optimization algorithm on hierarchical problem

I am working on a planning problem involving:
a collection of planning entities each containing the planning variable A
a global planning variable B (contained in the planning solution)
Since I am a beginner with Optaplanner and planning optimization in general, I started on a simpler version problem, focusing on optimizing A with B modeled as a planning fact.
Now that I have a program successfully optimizing A given B. I want to implement a new solver optimizing both A and B. It turns out that the best optimization search strategy is to first select a B value, and then optimize A given that B value. This process should be repeated until an optimum is found (the problem at hand is hierarchical)
I am looking for advice on how to implement this with Optaplanner. I initially thought I would implement this as two phases (optimize B -> optimize A) but I now understand Optaplanner phases are not meant to do that. For example, the solver cannot loop over this ordered sequence of two phases.
Instead, I think I should implement a custom MoveSelector which starts with a move on B, and then an infinite list of A move..
What do you think ? Am I on the right track ?
Kind regards,
A and B are different stages, not different phases (in OptaPlanner terminology).
In multi-stage planning (see short entry in docs), it's basically 2 different solvers, with one feeding into the other. This is very common when A and B occur at different times (think strategic vs tactical vs operation planning) or due to Conway's law (the organization structure of the users). This is the easy solution and often also by far the most practical during change management for the business. It's the least risk. However, it's suboptimal (in theory at least).
The alternative is indeed to have multiple planning entities, which makes it one big planning problem. That is the perfect solution. That is challenging. Perfect can be the enemy of good. OptaPlanner's architecture supports it, but custom moves are indeed required (today in OptaPlanner 7.35), as the default move selectors won't escape local optima often enough.

how to keep track of planning variable assignment in optaplanner

Is there a way to access planning variable's assignment during planning?
In my use case, I want to assign a planning variable with certain status only one time only during planning. After that I don't want to use that planning variable.
I know that in optaplanner, a planning variable/problem fact can not change, so i can not change its status.
Is there a way to get list of planning variable assignment during planning so that in java code or drools file, i can avoid re-assignment if it has been used once?
Thanks!
Use a hard constraint to enforce that.
Yes, you could use MoveFilters too, but that's not a good idea because sometimes you need to break hard constraints to escape local optima.

Optaplanner select only entities in conflict

In the change and swap move selector, I would like to only consider moves that involve entities in conflict as they are more likely to improve the heuristic score.
How should this be done? What classes and interfaces do I have to reuse/extend? I looked at ScoreDirector and PhaseLifecycleListener.
A MoveFilter might do that (if it's not in phase or solver cached as it changes ever step). See the course scheduling example and docs for how to use a filter.
I wouldn't recommend it though, as you still want to move non-conflicting entities at times. You might just want to focus more on those conflicting lectures. So I would keep a vanilla move selector in the mix.
The move filter isn't perfect either - the Guided Local Search feature (not yet available) is a better way to deal with this.
However, given the other question about the model and similar cases I 've seen, I 'd say moves are not your problem. A better model will make all these kinds of move tweaking obsolete.

What is the "right" way to get a list(or more generically, just an object) available multiple places?

In a program that I'm responsible for, we want to start keeping track of milestones. These milestones are quite simple and consist of a unique identifier, the project they're assigned to, a description, and a date that they should be accomplished by (or not, if there's no concrete due date).
We use a slightly modified Model-View-Presenter architecture, and currently I'm passing this list around through the presenters, but it seems fairly clunky, so I was wondering:
What's the best way to make this list available to all the presenters/views that need it?
We're using VB.NET 3.5, and I was toying with the idea of making this a shared property of the main presenter, but it does seem like that adds some unnecessary coupling.
I agree with Oded about keeping it as you have it, but if you insist on having it the way you describe, you could consider implementing it (the collection) as a singleton.
Have a read through this article