Can we Optimise the travel distance in VRPTW by using only one Vehicle? - optaplanner

Is it Possible to optimise the VRPTW by using only one vehicle.Since the single vehicle must go to the customer in sequence of the appointment time of customers.

Yes, it is. In the VRPTW example, simply add only 1 Vehicle instance in the Solution's vehicleList.
Academically, that's more a TSP(TW) than a VRP(TW) though.

Related

Optaplanner inventory allocation

I am trying to work with Optaplanner in order to solve the following simple exmample :
https://www.gams.com/products/gams/gams-language/#the-gams-language-at-a-glance/
simple inventory allocation exemple
I find it very difficult to do so since I couldn't find a similar cas on optaplanner
Can anyone help ? some directions, ressources
thanks in advance
It looks like the Facility Location Problem in OptaPlanner Quickstarts, but a consumer can pull from 2 or more suppliers at the same time.
Because the number of units to ship from supplier A to consumer X is an integer (*), you would need to use continuous value ranges and custom moves like in the investment example. Not simple (unlike other use cases in OptaPlanner), but doable.
(*) These business requirements are maybe unrealistic: in the real world, a half-full truck is almost as expensive as a full truck.

Implementing vehicle routing problem with profits variant using Optaplanner

I'm trying to use Optaplanner to implement the "VRPP" variation, where all customers don't need to be delivered to.
It seems like the example code I'm use for time windowed VRP ensures that all customers are in the "chain". I want to make that optional and then add to the score if they are in the chain. (If the "profit" of visiting them improves the score more than the cost they would be in the chain.)
I had assumed the problem was initialized with a complete chain and then moves only swapped positions, but I can't where or if that is happening.
Has someone implemented VRPP with optaplanner?
Read overcontrained planning in the docs, this about not having to assign all assignments.
Normally, you would be able to use nullable=true, but the new #PlanningListVariable doesn't support that yet, and neither do the old #PlanningVariable(CHAINED) (only if chained).
Introduce a dummy vehicle (with a field boolean dummy = true). Ignore the dummy vehicle for all hard and soft constraints. Use HardMediumSoftScore. Add a medium constraint to penalize all dummy vehicle assignments. Or instead add a medium/soft constraint summing the profit per assigned customer.

How to declare Optimization function?

I am working on the Vehicle Routing Problem.
My question is, we have to Minimise the total Distance covered by the Vehicle.
Where in the code we specify we have to Minimise the distance covered?
In drl file we give all the Constraint for consideration.
What if I want to get Maxmium distance covered by Vehicle.
Could anyone help me in understanding where to specify Max/Min for the given problem?
Or guide me to any tutorial/document to get an answer to this question?
Thanks
To maximize the distance covered by the vehicles in total, simply replace penalize with reward for that constraint. That will trigger a positive score instead of a negative score impact for each distance unit (km or time). It will replace the stick with the carrot for OptaPlanner.
Do note that won't load balance the distance per vehicle. A solution with two vehicles of distance 100 each (totaling 200) will be cast aside for a solution with one vehicle distance 300 and one vehicle distance 10 (totaling 310). Load balancing is possible too, see the docs section on "fairness".

Object condition in multiple places/repeated code (DRY)

This is a fundamental application design question I’ve struggled with and flip-flopped on for years. We have a legacy webapp that doesn't really have a solid ORM, if that tidbit might influence your answer. To abstract my question let’s say we have a class Car, and a corresponding table in our database named car. Car has a few properties: color, weight, year, maxspeed These properties directly correspond to columns in the db table.
In our application, we define the car as “classic old” if year is < 1960 and color = black. And in many places within our app knowing whether the car is "classic old" is extremely important (maybe we’re running a very illogical insurance agency which gives steep discounts and other perks to cars which are “classic old”).
All over our application, we do things like:
--list all classic old cars
--give the current user a discount if their car is classic old
--list all classic old cars with max speed > 100 miles per hour
--email the current user if their car is classic old and weights more than 1000 pounds
What is the best way to go about this? We have a legacy application that does this in some places:
getOldClassicCars()
select * where year < 1960 and color = black
and in other places:
cararray = getAllCars();
for each car in cararray
if car.year < 1960 and car.color = black
oldcararray = car.add()
The point being that this very important, fundamental piece of our application – is the car classic old – is “hardcoded” as year < 1960 and color = black in many places. Sometimes in SQL, sometimes in application code, etc. Obviously that is not good, but as we’ve refactored things I’m not sure we’re refactoring things the best way we can.
Well, you are stuck with the fundamental problem that
you cant run your code on the database
you want to be able to use the database's selection functionality on this criteria.
you want the calculation of "classic old" to be defined in a single place (preferably code)
Lets enumerate the solutions
1: Put the calculation in a sproc and always use the sproc to retrieve cars.
The problem here is if you create a new car in code, its class status is undefined, so you haven't really solved the 'not in two places' problem.
2: Get the DB to run your calc via an assembly. for example you can get mssql to run functions from a .net assembly which you can also use in your code base to perform the same calculation.
Problem, its hard work. Plus essentially its still in two places, you have to keep the db up to date and ensure that the table is accessed correctly
3: Persist the calculated value on the DB, but perform the calc in the code
Problem, if the calculation changes the DB values will be incorrect and need updating.
3 seems to be the best option, as we will know when the calculation changes and be able to take some action to resolve the situation.
However, it might be best, given the fundamental nature of this calculation, to make that 'out of dateness' implicit in the way we structure the code.
Instead of simply persisting car.IsClassic we could add a CarStatusReport object with a datetime property. We then generate a CarStatusReport(2017) which evaluates all the cars at that point in time and saves that data in a separate table.
Our business logic is then no longer, "Is this car a classic?" but "What does the latest CarStatusReport say the status of this car is?"
You Business Logic will then reside in a single CarStatusReportGenerator service and any other logic accessing the IsClassic calculation, will be forced to acknowledge the ephemeral nature of the stored info.
No optimal solution here. But, one good point will be to move all the business logic into the one place. If you can't (when you make methods or functions calculating some property, for example isOld()) then hide all those inconsistencies under the hood, so implementation users (conceptually) will never notice DRY violation from outside.

Optaplanner: how to handle minimum number consecutive

Let's assume a variation on Nurse Rostering example in which instead of assigning a nurse to a shift on a day, the nurse is assigned to a variable number of timeblocks on that day (which consists of 24 timeblocks). eg: Nurse1 is assigned to timeblocks [8,9,10,11,12,13,14]. Let's call these consecutive assignments a ShiftPeriod. There is a hard minimum and maximum on these shiftperiods. However, optaplanner has difficulties finding a feasible solution.
When having hard consecutive constraints, is it better to model the planning entity as a startTimeBlock with a duration instead of my current way with assignment to a timeblock and a day and then imposing min/max consecutive?
Take a look at the meeting scheduling example on github master for 6.4.0.Beta1 (but the example will work perfectly with 6.3.0.Final too). Video and docs coming soon. That example uses the design pattern TimeGrains, which is what you're looking for I think.