Jump to content

Separar Arraylist


Darmendes
 Share

Recommended Posts

Boas,

Estou a implementar um algoritmo rotas de veiculos, algumas notas:

  • cada veiculo tem o max de capacidade Y;
  • x clientes por rota ( tendo em conta a capacidade do veiculo);
  • Varias rotas

O meu programa calcula saving , ordena e ja cria rotas, mas acontece que criou uma unica rota com todos os clientes , porque ainda nao coloquei a limitacao do veiculo , para assim criar varias rotas... ja fiz varios tentativas e nao consegui šŸ˜ž

A ajuda que procuro e: quero num for each que soma o valor dos elementos enquanto for menor que a capacidade do veiculo: <x,y> , 6 (coordenadas (x,y) , volume da encomenda), agrupando em pequenas rotas

Ex .ArrayList [ <x,y> , 6 ; <x,y> , 7, <x,y> , 8 <x,y> , 4 ,<x,y> , 6, <x,y> , 5 ,<x,y> , 1, <x,y> , 2]

ArrayList [ soma 6+ 7 +8 ] new route, [4+6+5+1+2] new route , etc

para uma capacidade max 30:

quando aplico a condicao max 30, a minha rota so adiciona ArrayList [ soma 6+ 7 +8 ] ...

No fundo o que preciso mesmo e somar em grupo ...

//ArrayList para os nodes

List<List<Customer>>RoutesList;

RoutesList = new ArrayList<List<Customer>>();

//ArrayList<ArrayList<Customer>> RoutesList = new ArrayList<ArrayList<Customer>>(); //nodes

List<Customer> route = new ArrayList<Customer>();//nodeList

// //nodes.add(nodeList);

Order by Savings && Groupby NodeA:

Depot-A: Point2D.Double[240.0, 52.0] A_cap: 9 Depot-B: Point2D.Double[97.0, 324.0] B_cap: 4 Saving: 60.90871290356017 Total: 13

Depot-A: Point2D.Double[470.0, 441.0] A_cap: 6 Depot-B: Point2D.Double[240.0, 52.0] B_cap: 9 Saving: 37.68762785771156 Total: 15

Depot-A: Point2D.Double[470.0, 441.0] A_cap: 6 Depot-B: Point2D.Double[97.0, 324.0] B_cap: 4 Saving: 70.37988753481477 Total: 10

Depot-A: Point2D.Double[190.0, 262.0] A_cap: 8 Depot-B: Point2D.Double[470.0, 441.0] B_cap: 6 Saving: 20.20502757063946 Total: 14

Routes:

Route: 1 [Point2D.Double[240.0, 52.0], Point2D.Double[97.0, 324.0], Point2D.Double[470.0, 441.0], Point2D.Double[190.0, 262.0], Point2D.Double[423.0, 292.0], Point2D.Double[140.0, 56.0], Point2D.Double[46.0, 264.0]], etc

Obrigado

Edited by Darmendes
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.