Consider the combinatorial optimization problem described as below.
Let $D=(V,A)$ be a directed graph with $V$ the set of vertices and $A$ the set of arcs, i.e., $A=\{(i,j)\mid i,j\in V\}$. On each arc $a\in A$, there is a reward $r_a$ associated with it. The optimization problem is to form one or more cycles using the arcs, with each arc used in no more than one cycle. The cardinality of the cycle(s) cannot be more than a given number $K$. The objective is to maximize the sum of rewards for the arcs used in the cycles.
The major differences between this problem and the well-known Asymmetric Travelling Salesman Problem (ATSP) are as follows.
A solution that contains more than one "subtour" is considered feasible, however, the size of each subtour must be no more than $K$ vertices.
A feasible solution does not necessarily have to involve all vertices in $V$.
The objective is to maximize total reward of arcs used instead of to minimize the total cost of arcs used.
Let:
$x_{i,j}\in\{0,1\}$ be a binary variable with $x_{i,j}=1$ indicating arc $(i,j)\in A$ is used in the solution and $0$ otherwise;
$\Bbb P_K$ be the set of all simple paths with exactly $K$ vertices; and
$\tau=(i_1,\ldots,i_K)\in\Bbb P_K$ be an arbitrary simple path with exactly $K$ vertices, i.e., the arcs in the path are $(i_1,i_2),(i_2,i_3),\ldots,(i_{K-1},i_K)$.
An integer linear programming (ILP) model is given as below. \begin{align}\max&\quad\sum_{(i,j)\in A}r_{ij}x_{ij}\tag1\\\text{s.t.}&\quad\sum_{(i,j)\in A}x_{ij}\le1,&\quad\forall i\in V\tag2\\&\quad\sum_{(j,i)\in A}x_{ji}=\sum_{(i,j)\in A}x_{ij},&\quad\forall i\in V\tag3\\&\quad x_{i_1,i_2}+x_{i_2,i_3}+\cdots+x_{i_{K-1},i_K}-x_{i_K,i_1}\le K-2,&\quad\forall(i_1,\ldots,i_K)\in\Bbb P_K\tag4\\&\quad x_{ij}\in\{0,1\},&\quad\forall(i,j)\in A\tag5.\end{align}
Can someone help with writing up constraint $(4)$ in CPLEX? I don't how to write this one constraint, can you do it for $K=4$?
My code is currently as follows.
int K =...;
int nbVertices =166;
range Vertices =1..nbVertices;
int Reward[Vertices][Vertices] = ...;
dexpr int totalReward = sum (i in Vertices, j in Vertices)Reward[I]
[j]*Arc[i][j];
maximize totalReward;
subject to {
forall(i in Vertices)
sum(j in Vertices)Arc[i][j] <=1; //constraint (2)
forall(i in Vertices)
sum(j in Vertices)Arc[j][i] == sum(j in Vertices)Arc[i][j];//(3)
forall(i,j,k,l in Vertices: i!=j && j!=k && k!=l && l!=i) Arc[i][j]+
Arc[j][k] + Arc[k][l] - Arc[k][i] <= K-2; //constraint (4)
i!=j&&j!=k
does not guarantee thati!=k
, for example. $\endgroup$