Untitled

 avatar
unknown
c_cpp
2 years ago
908 B
4
Indexable
% 输入参数
int: n;
set of int: MEMBER = 1..n;
set of int: POSN = 1..n;
int: President = 1;
int: Secretary = 2;
int: Treasurer = 3;
int: Other = 4;
set of int: POSTYPE = 1..4;
array[MEMBER] of set of MEMBER: notwithPresident;
array[MEMBER] of set of MEMBER: notwithSecretary;

% 决策变量
array[MEMBER] of var POSTYPE: position;

% 约束条件
constraint forall(i in MEMBER) (
  position[i] = President -> (
    forall(j in notwithPresident[i]) (
      (position[j] != Secretary) /\ (position[j] != Treasurer)
    )
  )
);

constraint forall(i in MEMBER) (
  position[i] = Secretary -> (
    forall(j in notwithSecretary[i]) (
      (position[j] != President) /\ (position[j] != Treasurer)
    )
  )
);

include "alldifferent.mzn" ;

constraint global_cardinality(position, [1,2,3,4], [1,1,1,n-3]);

% 求解目标
solve satisfy;

% 输出结果
output ["Position assignments: "] ++ [show(position)];
Editor is loading...