subject to st {i in N, j in N : i < j} : X[i] != X[j];
subject to st : min {i in N, j in N : i < j} (abs(X[i] - X[j])) = 1;
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Thanks, very interesting!
This for *abs(A,B)*/*min(A,B)*/*max(A,B)*. How it method to convert for *min
{i in N} X* and *abs(X-X[j])*? Hard...
суббота, 23 июня 2018 г., 7:10:16 UTC+5 пользователь AMPL Google Group
написал:
On Sat, Jun 23, 2018 at 2:09 AM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
You can linearize your minimum and absolute function. You can find some resource about it at https://www.leandro-coelho.com/how-to-linearize-max-min-and-abs-functions/ .
--
Dr. Paras Tiwari
am...@googlegroups.com
Yes, X is variable
set Primes := {3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};
param n := 3; set N := 1..n; set N4 := 1..n*4; set NN := 1..n*n; set K := 1..49;
set P ordered := {p in Primes : p >= 13 && p <= 79};
param A {i in N, j in N} := if ((i+j-1) mod n)==0 then n else (i+j-1) mod n;
param I {i in NN} := i div n + if i mod n = 0 then 0 else 1;
param J {i in NN} := if i mod n = 0 then n else i mod n;
var X {N, N} integer in K;
var S {N4} integer in P;
s.t. st1 {i in N} : S[ i] = sum {j in N} (X[i,j]);
s.t. st2 {i in N} : S[ n+i] = sum {j in N} (X[j,i]);
s.t. st3 {i in N} : S[2*n+i] = sum {j in N} (X[j,A[i,j]]);
s.t. st4 {i in N} : S[3*n+i] = sum {j in N} (X[A[i,j],n-j+1]);
#s.t. stX : alldiff {i in N, j in N} (X[i,j]);
var Y {i in NN} = X[I[i],J[i]];
var Xb {i in NN, j in NN : i < j} binary;
s.t. stX {i in NN, j in NN : i < j} : Xb[i,j] = 1 ==> Y[i] <= Y[j] - 1 else Y[i] >= Y[j] + 1;
#s.t. stS : alldiff {i in N4} (S[i]);
var Sb {i in N4, j in N4 : i < j} binary;
s.t. stS {i in N4, j in N4 : i < j} : Sb[i,j] = 1 ==> S[i] <= S[j] - 1 else S[i] >= S[j] + 1;
minimize s : sum {i in N, j in N} (X[i,j]);
option solver gurobi;
option gurobi_options 'logfreq=10 outlev=1 timing=1 threads=3';
#option solver cplex;
#option cplex_options 'timing=1 threads=3 display=1 mipdisplay=4 mipinterval=10000';
#option solver xpress;
#option xpress_options 'timing threads=3 outlev=1 miplog=-10000 lplog=10000';
solve;
printf ("\nSum = " & s & "\n{{");
printf {i in N, j in N} (X[i,j] & (if j < n then "," else (if i<n then "},{" else "}}\n")));
Thanks!!!
With model below Gurobi worked, but Cplex and Xpress crashed
set Primes := {3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101};
param n := 3; set N := 1..n; set N4 := 1..n*4; set NN := 1..n*n; set K := 1..49;
set P ordered := {p in Primes : p >= 13 && p <= 79};
param A {i in N, j in N} := if ((i+j-1) mod n)==0 then n else (i+j-1) mod n;
param I {i in NN} := i div n + if i mod n = 0 then 0 else 1;
param J {i in NN} := if i mod n = 0 then n else i mod n;
var X {N, N} integer in K;
var S {N4} integer in P;
s.t. st1 {i in N} : S[ i] = sum {j in N} (X[i,j]);
s.t. st2 {i in N} : S[ n+i] = sum {j in N} (X[j,i]);
s.t. st3 {i in N} : S[2*n+i] = sum {j in N} (X[j,A[i,j]]);
s.t. st4 {i in N} : S[3*n+i] = sum {j in N} (X[A[i,j],n-j+1]);
#s.t. stX : alldiff {i in N, j in N} (X[i,j]);
var Y {i in NN} = X[I,J];
var Xb {i in NN, j in NN : i < j} binary;
s.t. stX {i in NN, j in NN : i < j} : Xb[i,j] = 1 ==> Y <= Y[j] - 1 else Y >= Y[j] + 1;
#s.t. stS : alldiff {i in N4} (S);
var Sb {i in N4, j in N4 : i < j} binary;
s.t. stS {i in N4, j in N4 : i < j} : Sb[i,j] = 1 ==> S <= S[j] - 1 else S >= S[j] + 1;
minimize s : sum {i in N, j in N} (X[i,j]);
option solver gurobi;
option gurobi_options 'logfreq=10 outlev=1 timing=1 threads=3';
#option solver cplex;#option cplex_options 'timing=1 threads=3 display=1 mipdisplay=4 mipinterval=10000';
#option solver xpress;#option xpress_options 'timing threads=3 outlev=1 miplog=-10000 lplog=10000';
solve;
printf ("\nSum = " & s & "\n{{");
printf {i in N, j in N} (X[i,j] & (if j < n then "," else (if i<n then "},{" else "}}\n")));