# How to solve a CVRP?

• 22 replies
• 159 views

Hi Community.. Please how can i create a sen and subset with 10 Cities? where the Citie 1 is the Depot? ..

What exactly is the problem you are running into?

You can define a set in AIMMS that is called cities and use the definition field to define the 10 cities (You can click on the wizzard button next to definition to use the GUI to add the elements).

If you just have one depot, you can make an element parameter that has this new set as range and as definition give it the value of the depot-city. Alternatively, if you have potentially more depots, you could make depots a subset of the cities.

Type: Set

Identifier: Cities

Index: i,j;

Definition: data { A, B, C, D, E, F, G, H, I, J}

From A to J for the 10 Cities and A is the Depot

The Distance Data is Symetric.. I dont know how to do, to see the Cities (i, j) Tableau, so i can give the Distance number in the parameter area?

Cities (and the indices i and j) are the set and the corresponding indices.

If you want to define a distance between two cities, you have to define a new parameter, for example pDistance(i,j)

If you then go into the data for this parameter (or the definition wizard), you will be able to enter the distances between each pair.

These are really the basic steps in AIMMS. Would recommend you to take a look at the Aimms Tutorial for beginners, which covers these type of topics (saw they even have a video about it). You can find it at https://how-to.aimms.com/Articles/505/index.html  (and then just keep clicking on the next button in the bottom right)

thank you so much to take your time to help me .. sorry englisch is not my main Language..

So i did the tutorial for beginner with plants and customers and it runs very good.. By the CVRP i declared the set of citie I and the Set of Vehicle K..i enter the Distance between cities too. know i have 2 Problem .. i cant declare the second Variable x(i,i,k).. And how to write the formule of objektive Funtion in the Definition arel von pTotaldistance? sum(i to I)*sum(j to I)*sum(k to K) *pdistance* x(i,j,k)

If you want to use a set twice as index for a parameter or variable, you will have to use two different index names.

So it would be variable x(i,j,k)

Since I am assuming distance is only defined for the combinations (i,j)  and is independent of the vehicle k, you can write the objective variable (must be a variable, not a parameter if it changes values during the optimization!) vTotalDistance with the following definition:

sum( (i,j,k) ,  pDistance(i,j) * x(i,j,k) )

Which means, loop over all combinations of (i,j,k) and take the sum of every multiplication of pDistance(i,j) with the decisionVariable x(i,j,k)

i Declared the depot as Element Paramter and become this answer:The  expression is of type set while expecting an expression of type element.

how can i write the contraints 3 and 4? i bekomme die answer:The scope of index "j" has not been specified.

i Declared the depot as Element Paramter and become this answer:The  expression is of type set while expecting an expression of type element.

The problem is that an element parameter is just a single element, not a set. The construct you are using there (with data {1} ) is to define a set.

If you are not really sure about the syntax, would recommen you use the little wizard button left of your text data to define the content of the definition attribute.

how can i write the contraints 3 and 4? i bekomme die answer:The scope of index "j" has not been specified.

Without you showing what you are trying, it is impossible to figure out why you are getting that particular error.

Please note that you can actually download this library and include it in your project (the instructions for that are also on the page). After that, you can see the definitions of the constraints used in the article.

https://how-to.aimms.com/Articles/332/332-Formulation-CVRP.html

Thank u for your Help i try with Library and it seems to work..

only the last Question : The Parameter NumberOfvehicles is: 4 .. why it dont runs?

You need to provide more details…

The error seems to indicate that there are no variables (or they can all only take the value 0), which would result in a generated constraint  (with all variables on the left and regular numbers on the right)

0 = 4

Did you define Y as a variable in AIMMS? Can you show the definition of the set belong to index k and the attribute window of the identifier Y?

i fixed it.. The Problem was the Element Parameter of Depot..

Now after running i become this answer: Warning: After 1172033 iterations CPLEX 22.1 concluded that an integer solution to LeastCost does not exist.

This is a problem that can have multiple causes, it could be an error in your math model, but it could also be a problem in the data that does not allow for a feasible solution due to the constraints.

Thank you so .. Now it Runs in RMIP … the last Question  .. How can i do to see the Input out put Window?

Note that RMIP means it is the relaxed MIP, meaning you are not solving an integer problem anymore.

With regards to your input/output window, not really sure what you mean. There is no generic input/output window for a model in AIMMS, you would have to use either the winUI or the webUI to construct pages that contain one or more widgets that display the contents of identifiers (e.g. a pivot table showing which truck is serving which cities, etc).

After a solve is finished, you can always press the data button (or use Ctrl-D shortcut) after you opened the attribute window of a variable/parameter

Nor it Run in MIP too..i fixed the Input and Output Page too .. i Work for the First Time with AIMMS and it so good ..i can speak about my experience at the University.

Now i wann put at time Restriktion in mein CVRP...so each Car can only Drive 200 Minute. Please how can i Formulate this. IT will BE my very Last question

I have a Distance between i and j , evry Car habe a Velocity of  20 Kilometer in 200 Minute.. so i need a Restriktion that each Car can only Drive 20 Kilometer or 200 Minutes

I don’t know the details of you model, but you would need to figure out which variables to sum up and ensure they are constrained to 200 minutes / 20km.

For sure, since you need to have this constraint for every car, you will need to put k in the index domain for this constraint. For the definition you need to determine how to create the sum

Hi .. how can i declare the Identifer x color? please

You will have to work with element parameters in the set allColors. Please see https://documentation.aimms.com/user-guide/miscellaneous/user-interface-language-components/setting-colors-within-the-model.html for more information.