Non linear cost function

Hi,
I try to build a cost functon of a vehicle with dynamic costs. Until now I use:

  • setFixedCost(double)
  • setCostPerDistance(double)
  • setCostPerTransportTime(double)

Problem: e.G. between 0-5 hours threre are costs of X, later after 5 additional costs of Y (extra charge by time).

Formula for a vehicle: fixCost + (TransportTime * dynCostPrice) + (additionalTime * extraChargePrice)

Is it possible to represent this? How?

Kind regards
Volker

Hi Volker,

one way is to create your own Vehicle Routing Cost matrix. Have a look at the VehicleRoutingTransportCostsMatrix you should be able to easily adapt for your needs.

Best
Chris

Hi Chris,
thanks for your reply,
thats interesting, but I think that does not help.
The Question is how to calculate the tour cost (profit-function) of one vehicle with many stops and the first (cost) time window (e.g. 5 hours) are over and the timedependent costs after this are getting higher, but not the cost for one long distance beween two stops.

Regards
Volker

@softwareengel Have you got any solution to this ?

It’s a long time ago. We used the SolutionCostCalculator and overriding getCosts and calculate manually every cost for every solution , e.g. like this.

    SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {

        @Override
        public double getCosts(VehicleRoutingProblemSolution solution) {
            double costs = 0.0;
            for (VehicleRoute route : solution.getRoutes()) {
                // add fixed cost of the vehicle
                costs += route.getVehicle().getType().getVehicleCostParams().fix;
                TourActivity prevAct = route.getStart();
                for (TourActivity act : route.getActivities()) {
                    costs += problem.getTransportCosts().getTransportCost(prevAct.getLocation(), act.getLocation(),
                            prevAct.getEndTime(), route.getDriver(), route.getVehicle());
                    prevAct = act;
                }
            }
            return costs;
        }
    };

But the truth is, that we dismissed this approach an build our own solver…
Kind regards.

1 Like