-1

I've written following code for a clustering problem:

range N=1..10; 
range M=1..2; 
float distance[N,N]=...;
dvar boolean x[M,N]; 
dvar float+ Z; 

minimize Z;

 subject to {
   forall(i in N, j in N, k in M)
         distance[i,j]*x[i,k]+distance[i,j]*x[j,k]-Z<= distance[i,j];
  
   forall(j in N)
    sum(i in M)x[i,j]==1; }

I keep getting "CPLEX cannot extract expression" and "OPL cannot extract expression" errors. Am I writing the first constraint wrong?

Here's the mathematical model:model

1 Answer 1

0
range N=1..10; 
range M=1..2; 
float distance[n1 in N,n2 in N]=abs(n2-n1);
dvar boolean x[N,M]; 
dvar float+ Z; 

minimize Z;

 subject to {
   forall(i in N, j in N, k in M)
         distance[i,j]*x[i,k]+distance[i,j]*x[j,k]-Z<= distance[i,j];
  
   forall(j in N)
    sum(i in M)x[j,i]==1; }

works fine

2
  • thanks! it works but I've laready set the distance matrix, it's a 10x10 matrix let's say, and it has 0's diagonally ofc. In my previous code I tried to retrieve distance array from .dat file, but it didn't work, am I missing something?
    – Cmrs
    Commented Dec 5, 2023 at 19:34
  • Then change float distance[n1 in N,n2 in N]=abs(n2-n1); into float distance[N,N]=...; Commented Dec 6, 2023 at 10:31

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.