0

Is it possible to have two or multiple shipment in same route by hard Contraint.

If not, do you know other java libraries that can handle such kind of restrictions?

Thank you!

Stefan Schröder
  • 1,037
  • 7
  • 13

1 Answers1

1

The easiest way do make sure that shipments are in the same route is to tag these shipment with a skill

shipmentBuilder.addRequiredSkill("tag")

but then you need to tag a particular vehicle as well:

vehicleBuilder.addSkill("tag")

And make sure you make the algorithm consider skills/these tags (see https://github.com/jsprit/jsprit/blob/master/WHATS_NEW.md - you need to use 1.3.2-SNAPSHOT).

If you do not want to assign a particular vehicle with a tag, you need to implement a core.problem.constraint.HardRouteStateLevelConstraint which is basically this method

public boolean fulfilled(JobInsertionContext insertionContext)

Make sure that insertionContext.getJob() [which is the job to be inserted] can be inserted into insertionContext.getRoute(). At this point you need to know two things:

  • the associated shipments of insertionContext.getJob(), i.e. shipments that need to be in same route as insertionContext.getJob()
  • whether one of these associated jobs has already been assigned to a route and if so whether this route is the same as insertionContext.getRoute()

For latter information you need to define states that provides you with a job-route assignment. I would define a problemState and its according updater like this:

static class UpdateJobRouteAssignment implements StateUpdater,JobInsertedListener,InsertionStartsListener {

        StateManager stateManager;

        UpdateJobRouteAssignment(StateManager stateManager) {
            this.stateManager = stateManager;
        }

        @Override
        public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
            stateManager.putProblemState(stateManager.createStateId(job2insert.getId()), VehicleRoute.class, inRoute);
        }

        @Override
        public void informInsertionStarts(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
            for(VehicleRoute r : vehicleRoutes){
                for(Job j : r.getTourActivities().getJobs()){
                    informJobInserted(j,r,0.,0.);
                }
            }
        }
    }

Add your state updater and your constraint to your State/ConstraintManager and you are done.

Stefan Schröder
  • 1,037
  • 7
  • 13
  • Optimisation of route steed: The problem is to model several courrier, each courrier consists of several tasks task 1, task 2 .., which must be in the same route and with respect for the order, 1 2 .., we are talking about steed work. for each courrier the first task has a time window. for courrier with just two task, I can modelize by Shipments, pickup as the first task and delivery the second, but for more than two ??? Any Idea?? Thank you. – mohamed elmaallem Sep 06 '14 at 10:36
  • I am sure you get help here: https://groups.google.com/group/jsprit-mailing-list. Just post it there again and you might catch users who solved a similar problem already. – Stefan Schröder Sep 08 '14 at 17:47