Constraints Minizine:这个约束可能吗?

Constraints Minizine:这个约束可能吗?,constraints,constraint-programming,check-constraints,minizinc,Constraints,Constraint Programming,Check Constraints,Minizinc,我想弄清楚如何编写这个约束:我有一个考试列表,每个考试都有一个持续时间;最后一个输出是实际时间表的显示,在列中有可用的小时,早上四点和下午四点,午餐中间有两个小时,这是不可用的。所以,让我把这一点弄清楚,如果我有两个考试,每个考试都有一个指定的持续时间,我想在时间表中显示与考试持续时间相关的考试次数,因为我的变量是考试 例如:我有两次考试,第一次考一个小时,第二次考三个小时 int: Exams; array[1..Exams] of int: Exams_duration; int: Sl

我想弄清楚如何编写这个约束:我有一个考试列表,每个考试都有一个持续时间;最后一个输出是实际时间表的显示,在列中有可用的小时,早上四点和下午四点,午餐中间有两个小时,这是不可用的。所以,让我把这一点弄清楚,如果我有两个考试,每个考试都有一个指定的持续时间,我想在时间表中显示与考试持续时间相关的考试次数,因为我的变量是考试

例如:我有两次考试,第一次考一个小时,第二次考三个小时

int: Exams;
array[1..Exams] of int: Exams_duration;


int: Slotstime;         % number of slots
int: Rooms;             % number of rooms
array[1..Slotstime,1..Rooms] of var 0..Exams: Timetable_exams;

%Data

Exams=2;
Exam_duration=[1,3];
Slotstime=4;            
我希望有这个输出:[1,2,2,2],而不是[0,0,0,4](在垂直模式下) 有可能用迷你锌做吗? 第二个输出的代码为:

constraint forall (p in 1..Rooms)                 
( 
  sum (s in 1..Slotstime) (Timetable_exams[s,p]) 
  = sum (f in 1..Exams)(Exams_duration[f])
);
提前感谢

(您好,这个问题比您原来的问题更容易回答,因为它更切题。)

这是一个使用两个额外的决策变量数组的版本:“ExamsRoom”用于处理考试的房间分配,而“ExamsStart”用于考试的开始时间。也许这些并不是真正必要的,但它们使陈述考试持续时间约束变得更容易;房间和时间的分配也更清楚地显示出来。它们还可能有助于添加更多约束

我还添加了参数“Rooms=2”,因为您的示例中缺少该参数

int: Exams;
array[1..Exams] of int: Exams_duration;

int: Slotstime;         % number of slots
int: Rooms;             % number of rooms
array[1..Slotstime,1..Rooms] of var 0..Exams: Timetable_exams;

array[1..Exams] of var 1..Rooms: ExamsRoom; % new
array[1..Exams] of var 1..Slotstime: ExamsStart; % new

solve satisfy;
% solve :: int_search(x, first_fail, indomain_min, complete) satisfy;

constraint

  % hakank's version

  % for each exam
  forall(e in 1..Exams) (
    % find a room
    exists(r in 1..Rooms) (
       % assign the room to the exam
       ExamsRoom[e] = r /\
       % assign the exam to the slot times and room in the timetable
       forall(t in 0..Exams_duration[e]-1) (
          Timetable_exams[t+ExamsStart[e],r] = e
       )
    ) 
  ) 

  /\ % ensure that we have the correct number of exam slots
  sum(Exams_duration) = sum([bool2int(Timetable_exams[t,r]>0) | t in 1..Slotstime, r in 1..Rooms])
 ;

output [
  if r = 1 then "\n" else " " endif ++ 
     show(Timetable_exams[t,r])
  | t in 1..Slotstime, r in 1..Rooms
 ]
 ++
 [
   "\nExamsRoom: ", show(ExamsRoom), "\n",
   "ExamsStart: ", show(ExamsStart), "\n",
 ]
 ;

 %
 % Data
 %
 Exams=2;
 Exams_duration=[1,3];
 Slotstime=4;            

 % was not defined
 Rooms = 2;
该模型有20种不同的解决方案,前两种(使用Gecode作为解算器)是

第一个解决方案意味着考试1在1号房间的时间4开始,考试2在1号房间的时间1开始。第二个解决方案具有与考试2相同的任务,但将考试1设置为房间2(在时间1)

希望这有助于您进一步使用该模型


/哈坎克

我看到你现在的情况已经大大改变了这个问题。这很令人困惑,因为你已经接受了答案。你最好撤销对原始问题的更改,然后写一个新问题。你是对的!回到原点!它将对其他人有用!
2 0
2 0
2 0
1 0
ExamsRoom: [1, 1]
ExamsStart: [4, 1]
----------

2 1
2 0
2 0
0 0
ExamsRoom: [2, 1]
ExamsStart: [1, 1]
----------