Endogeneus operands for * not allowed in linear models

my cvrp code here. But I have 1 error for z.How can I make it work in MIP format? can you help me ?

Set
   i    'düğüm noktaları'      /DEPO, K1*K28/
   k    'araçlar'              /T1*T2/;
   
Alias(i,j);

Parameters
   demand(i)
        /DEPO  0
         K1    1.5
         K2    1.2
         K3    2.3
         K4    3
         K5    2.3
         K6    6.4
         K7    2.8
         K8    3.5
         K9    4.9
         K10   6
         K11   4
         K12   3.2
         K13   2
         K14   2.2
         K15   5
         K16   5.1
         K17   1.1
         K18   1.7
         K19   1.9
         K20   3.2
         K21   2.4
         K22   3
         K23   4.4
         K24   2.6
         K25   1.4
         K26   2.2
         K27   3.1
         K28   2.1/
   capacity(k)
         /T1 70
          T2 20/;
   
   Table c(i,j) 'taşıma mesafesi km matris GERÇEK DEĞERLERİ 10 İLE ÇARPILMIŞ ŞEKİLDE'
     DEPO     K1      K2      K3      K4      K5      K6      K7      K8      K9      K10      K11      K12      K13      K14      K15      K16      K17     K18      K19      K20      K21      K22      K23      K24      K25      K26      K27      K28
DEPO 999999   86      40      76      629     575     585     598     592     587     631      666      207      166      207      353      543      171     544      76       444      554      564      84       28       56       70       60       630        
K1   86       999999  110     130     650     600     610     640     630     630     670      700      250      240      280      430      590      210     598      178      492      602      612      143      128      47       120      108      678
K2   40       110     999999  70      610     110     90      70      50      70      80       130      410      710      590      440      110      440     496      68       407      505      517      46       17       76       32       45       583
K3   76       120     58      999999  615     595     604     590     629     570     622      641      219      183      235      374      549      180     537      117      434      541      554      68       58       84       62       35       620
K4   629      710     590     633     999999  143     93      67      53      73      85       132      435      632      588      441      115      444     101      641      201      118      68       564      613      637      564      594      64
K5   575      643     527     568     450     999999  29      135     54      114     56       58       370      653      523      376      43       400     47       576      146      37       55       500      558      573      499      540      65
K6   585      653     537     578     80      24      999999  104     31      83      51       72       380      663      533      386      54       410     31       586      156      40       42       510      568      583      509      550      52
K7   598      664     562     591     63      105     83      999999  51      25      92       197      393      676      547      400      100      420     87       598      169      81       53       523      581      594      521      563      85
K8   592      660     544     586     50      57      43      74      999999  52      53       80       387      671      541      394      44       418     32       593      164      42       21       517      576      590      516      557      47
K9   587      657     541     582     56      96      75      15      42      999999  83       189      384      667      538      391      91       415     72       588      158      69       42       511      570      584      511      551      75
K10  631      699     583     625     93      71      49      145     46      93      999999   60       427      710      580      433      100      457     89       633      203      98       71       556      615      629      556      596      8.5
K11  666      703     586     628     131     59      75      183     80      174     57       999999   430      713      583      436      104      460     102      636      206      100      106      559      650      632      559      625      62
K12  207      312     170     237     448     394     374     400     399     379     421      440      999999   297      349      540      338      37      339      220      243      350      363      143      190      216      143      171      429
K13  166      245     148     202     640     579     559     584     583     563     605      625      342      999999   55       194      533      302     622      97       511      535      547      184      151      211      170      182      614
K14  207      285     183     224     595     533     513     538     533     517     560      579      383      48       999999   149      487      343     496      138      465      492      502      225      191      252      211      223      568
K15  353      431     335     388     450     389     368     394     393     373     415      432      532      194      150      999999   343      562     345      284      321      348      357      371      337      398      357      368      424
K16  543      610     495     537     110     42      41      100     45      79      45       92       338      621      492      34       999999   369     22       544      115      5.5      38       468      526      541      467      508      96
K17  171      215     135     175     482     429     408     434     433     413     455      474      53       262      313      453      383      999999  369      185      277      387      397      108      155      181      108      136      463
K18  544      598     496     537     101     47      31      87      32      72      89       102      339      622      496      345      22       369     999999   545      115      21       23       469      524      542      468      508      78
K19  75       178     68      117     641     576     586     598     593     588     633      636      220      97       138      284      544      185     545      999999   477      587      597      95       61       121      81       92       663
K20  443      492     407     434     201     146     156     169     164     158     203      206      243      511      465      321      115      277     115      456      999999   115      124      380      426      453      379      408      190
K21  547      602     505     541     118     37      40      81      42      69      98       100      350      535      492      348      5.5      387     21       548      118      999999   37       472      530      545      471      508      91
K22  581      612     517     554     68      55      42      53      21      42      71       106      363      547      502      357      38       397     23       582      153      37       999999   506      564      579      505      561      63
K23  82       143     46      68      564     500     510     523     517     511     556      559      143      184      225      371      468      108     469      99       362      463      472      999999   65       95       21       50       539
K24  28       128     17      58      613     558     568     581     576     570     615      650      190      151      191      337      526      155     524      64       428      538      547      67       999999   72       53       38       614
K25  40       47      76      84      637     573     583     594     590     584     629      632      216      211      252      398      541      181     542      137      451      551      561      102      78       999999   79       66       627
K26  67       120     32      62      564     499     509     521     516     511     556      559      143      170      211      357      467      108     468      85       388      488      498      31       49       79       999999   27       564
K27  52       108     45      35      594     540     550     563     557     551     596      625      171      182      223      368      508      136     508      92       401      511      521      41       535      64       29       999999   587
K28  609      678     583     620     64      65      52      85      47      75      8.5      62       429      614      568      424      96       463     78       623      193      80       63       546      591      619      546      574      999999;

Binary Variable
   x(i,j,k)    'Eğer araç k depolar arasında i den j ye gidiyorsa 1, aksi takdirde 0'
   y(i,k)      'Eğer araç k, depo i yi ziyaret ediyorsa 1, aksi takdirde 0'
   pass(i,j,k) 'Eğer araç k, depo i den j ye talep karşılamadan geçiyorsa 1, aksi takdirde 0'
   visit_without_service(i,k)'Eğer araç k, depo i ye gidip talep karşılamıyorsa 1, aksi takdirde 0';
;

Positive Variable
   load(i,k) 'Araç k nın depo i den ayrıldıktan sonra taşıdığı yük miktarı';

Variable z 'Toplam maliyet mesafe' ;

Equation
   obj                      'Amaç fonksiyonu: toplam mesafeyi minimize et'
   demand_satisfaction(i)   'Her deponun talebi bir araç tarafından karşılanmalı'
   capacity_constraint(k)   'Her aracın kapasitesi aşılmamalı'
   flow_conservation(i,k)   'Akış dengesi: araçlar geldiği yerden başka yere gitmeli'
   load_flow(i,j,k)         'Araç akışını takip etme (yük akışı kısıtı)'
   start_load(k)            'Araçlar ana depodan tam kapasiteyle başlar'
   return_to_depot(k)       'Her araç ana depoya dönmeli'
   visit_without_service_constraint(i,k)   'Eğer araç depo i ye gidip talep karşılamıyorsa 1 yapar'
   must_return_if_no_service(k)   'Araç talep karşılamazsa ana depoya dönme zorunluluğu';

* Amaç fonksiyonu: toplam mesafeyi minimize et
obj ..
   z =e= sum((i,j,k), c(i,j) * x(i,j,k));

* Her depo bir araç tarafından ziyaret edilmeli
demand_satisfaction(i)$(not sameas(i,'DEPO')) ..
   sum(k, y(i,k)) =e= 1;

* Her araç kapasitesi aşılmamalı
capacity_constraint(k) ..
   sum(i$(not sameas(i,'DEPO')), demand(i) * y(i,k)) =l= capacity(k);

* Akış dengesi: bir depoya gelen araç, o depodan başka bir yere gitmeli
flow_conservation(i,k)$(not sameas(i,'DEPO')) ..
   sum(j, x(i,j,k)) =e= y(i,k);

* Yük akışını takip et: yük azalmalı
load_flow(i,j,k) ..
   load(j,k) =e= load(i,k) - demand(j) * x(i,j,k);

* Araçlar ana depodan tam kapasiteyle hareket etmeli
start_load(k) ..
   load('DEPO',k) =e= capacity(k);

* Her araç ana depoya geri dönmeli
return_to_depot(k) ..
   sum(i, x(i,'DEPO',k)) =e= 1;

* Araç bir depoya gidiyorsa ve talep karşılamıyorsa ana depoya geri dönmeli
visit_without_service_constraint(i,k)$(not sameas(i,'DEPO')) ..
   visit_without_service(i,k) =e= sum(j, x(i,j,k)) * (1 - y(i,k));

* Araç talep karşılamıyorsa ana depoya dönme zorunluluğu
must_return_if_no_service(k) ..
   sum(i$(not sameas(i,'DEPO')), visit_without_service(i,k)) =e= sum(i, x(i,'DEPO',k));

* Model tanımı ve çözüm
Model CVRP /all/;
Solve CVRP using mip minimizing z;

Hi, this is a non-linear equation. I think you must define a new binary variable for the product of two binary variables.

visit_without_service_constraint(i,k)$(not sameas(i,‘DEPO’)) … visit_without_service(i,k) =e= sum(j, x(i,j,k)) * (1 - y(i,k));

You can try with a new binary variable w(i,j,k) that by restrictions is equivalent to the product of binary variables: x(i,j,k)*y(i,k)

visit_without_service_constraint(i,k)$(not sameas(i,‘DEPO’)) … visit_without_service(i,k) =e= sum(j, x(i,j,k))  -  sum(j, w(i,j,k));
visit_without_service_constraint_a(j,i,k)$(not sameas(i,‘DEPO’)) … 1 - x(i,j,k) + 1 - y(i,k) + w(i,j,k) =g= 1;
visit_without_service_constraint_b(j,i,k)$(not sameas(i,‘DEPO’)) … w(i,j,k) =l= x(i,j,k);
visit_without_service_constraint_c(i,k)$(not sameas(i,‘DEPO’)) … w(i,j,k) =l= y(i,k);

Please check that it is okay
best

In your constraint visit_without_service_constraint you multiply variables and that’s not allowed in a MIP. Since this is a binary*binary you can easily linearize this. Search the forum for linerarizing logical constraints and you will find some pointers.

I looked at your model and some things in isolation don’t make much sense: In flow_conservation you defined y(i,k) to be equal to sum(j, x(i,j,k)). Hence in constraint visit_without_service_constraint on the right hand side you have sum(j, x(i,j,k)) * (1 - y(i,k)) which read with the previous constraint y(i,k)*(1-y(i,k)). With y being a binary variable, this product will always be 0.

-Michael

1 Like