Page **1** of **1**

### Division by zero for division of two continuous variables

Posted: **Sat Jun 02, 2018 11:33 pm**

by **moosavi_69**

Dear friends,

I have coded a facility layout problem as a MINLP model. Then, I used Baron as the default solver. In this model, constraint 19b determines the maximum distance between whole departments (DmaxF, a positive variable). Then, this variable is used on the right-hand sides of constraints 22a and 22b. When I run the model, I face an error called division by zero, which is related to constraints 22a and 22b.

But when I replace DmaxF with a constant, e.g., 40, in constraints 22a and 22b, the model solves the problem with no error. Surprisingly, the results show that DmaxF gets positive values (DmaxF <> 0).

Could you please help out? Note that I have attached a .gms file containing all information required for guidance!

Regards,

Amir

### Re: Division by zero for division of two continuous variables

Posted: **Sun Jun 03, 2018 12:29 pm**

by **Renger**

Hi Amir

In equation 18b, you use the sqrt function and as Gams initializes variables to 0, you get an error.

If I initialize these variables with a random number, the model starts solving using BONMIN (I don't have a license for DICOPT).

Code: Select all

```
x.l(i,t) = uniform(1,10);
y.l(i,t) = uniform(1,10);
```

I used a random initializiaton as you subtract x(j,t) from x(i,t) (same for y). Initializing them with the same values would results in zeros.

Hope that this solves the problem

Cheers

Renger

### Re: Division by zero for division of two continuous variables

Posted: **Sun Jun 03, 2018 1:13 pm**

by **moosavi_69**

Renger wrote: ↑2 years ago

...

I used a random initializiaton as you subtract x(j,t) from x(i,t) (same for y). Initializing them with the same values would results in zeros.

...

Renger

Hi Renger,

First of all, I have to appreciate your attention. As per as your valuable comment, I have added the following lines to the code (next to the place I had defined variables), but it does not work even now!

Code: Select all

```
execseed = 1e8*(frac(jnow));
loop(i,
loop(t,
x.l(i,t) = uniform(1,10);
y.l(i,t) = uniform(1,10);
);
);
```

or

Code: Select all

```
x.l(i,t) = uniform(1,10);
y.l(i,t) = uniform(1,10);
```

Do you have any idea? I have attached a new file in which x and y initialize from random values rather than zero.

Thx a GALAXY

### Re: Division by zero for division of two continuous variables

Posted: **Mon Jun 04, 2018 8:16 am**

by **Renger**

Hi

Here it is exactly the same problem: you did not initialize DmaxF, so add DmaxF.l(t) = 1; and it works.

You don't need a loop for assigning values to x and y. As long as the index of the variables on the LHS is equal to the RHS in the assignment, without a loop the assignment works well.

Cheers

Renger

### Re: Division by zero for division of two continuous variables

Posted: **Mon Jun 04, 2018 9:02 am**

by **moosavi_69**

I also found another solution to this problem, specifically for the Baron solver. If you add the following code, the Baron could ignore the error and try to find a feasible solution. I think there should be similar options for other solvers as well. But what you mentioned, is a solution for all solvers! Thank you very much. My code works right now.

Code: Select all

```
MaxExecError = 100000;
Option sys12 = 1;
```