can anyone Help improving this algorithm I made

+2 Thomas Connachan · November 10, 2014

So I Made this algorithm to solve a VRP which at the moment is very bad algorithm but I am not sure how to improve it, Does anyone have any ideas on how I could improve it.

If I am honest I am not entirely sure it does what I want it to at the moment either

It should make a route eg route A: and fill it with customers untill its at capacity, Then make a route eg Route B when A it full and add customers until route B is full and so on

thanks for any help

// Create a route for a customer and add a new customer untill the route is 
// at capacity then do the same for a new route untill all customers
// are in a route
public void testAlgo() {
this.soln = new ArrayList<List<Customer>>();
int max = this.prob.depot.c; // set max capacity to vans max
int current = 0; // set current capacity to 0

ArrayList<Customer> route = null; // set route to null
for(Customer c:prob.customers){ // for each customer in the problem
int req = c.c; //set the required amount for delivery 
if(current + req <= max){ //if current capacity plus req capacity is less than the max
route = new ArrayList<Customer>(); // make a route
soln.add(route); // add the route to soln
current = current + req; // add the req to the current to get the new current
route.add(c); // add customer to route

Post a Reply


Oldest  Newest  Rating
0 H. P. Lovecraft · November 11, 2014
Why is this algorithm bad, what is the current complexity?
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator