我目前正在研究 MiniZinc,并且我一直在使用 MiniZinc 中集成的两个求解器运行我的模型:Gecode 和 Chuffed。我一直在 IDE 中运行它,但我知道它也可以在 bash 中运行(使用minizinc命令)。
但我想测试我的模型如何使用 Google 的 CP 求解器,称为 OR-Tools。但我真的不知道怎么做。我在 Ubuntu 18.04 中安装了 MiniZinc snap,但我可以下载 MiniZinc 的新目录并在本地运行它,并在那里配置求解器(而不是在 snap 安装中,因为 snap 目录无法修改)。
我需要一种方法来安装 OR-Tools 并使其至少在终端中工作(但从 IDE 运行它会很完美)。
installation solver constraint-programming minizinc or-tools
I am a beginner in Constraint Programming using Minizinc and I need help from experts in the field.
How can I compute all the possible combinations: 6 Rectangles inside the Square (10x10) using Minizinc?
Considering that the RESTRICTIONS of the problem are:
1) No Rectangle Can Overlap
2) The 6 rectangles may be vertical or horizontal
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
我必须扩展项目的输出和解决方案(安排考试时间):
-将结构扩展到五天(我一直工作一天):我仔细考虑了插槽时间的天数(5 * 10),然后调整输出!有没有更好的办法?
现在整个代码:
include "globals.mzn";include "alldifferent.mzn";
%------------------------------Scalar_data----------------------
int: Students; % number of students
int: Exams; % number of exams
int: Rooms; % number of rooms
int: Slotstime; % number of slots
int: Days; % a period i.e. five days
int: Exam_max_duration; % the maximum length of any exam (in slots)
%------------------------------Vectors--------------------------
array[1..Rooms] of int : Rooms_capacity;
array[1..Exams] of int : Exams_duration; % the duration of written test
array[1..Slotstime, 1..Rooms] of 0..1: Unavailability;
array[1..Students,1..Exams] of 0..1: Enrollments;
Run Code Online (Sandbox Code Playgroud)
招生会跟踪每个学生的注册情况;从中我可以得出要参加考试的学生人数,以便根据能力选择合适的房间
%---------------------------Decision_variables------------------ …Run Code Online (Sandbox Code Playgroud) constraints check-constraints constraint-programming minizinc
我尝试在 MiniZinc 中使用字符串连接运算符定义约束,求解变量a和b:
include "disjunctive.mzn";
var string:a;
var string:b;
constraint("var1/var2" = (a ++ "/" ++ b));
solve satisfy;
output ["\nx=", show(a)];
Run Code Online (Sandbox Code Playgroud)
尽管如此,这似乎是一个语法错误:
MiniZinc: type error: type error in operator application for `++'. No matching operator found with left-hand side type `string' and right-hand side type `var string'
Run Code Online (Sandbox Code Playgroud)
是否仍然可以用字符串或数组作为变量来解决 MiniZinc 中的约束?
我正在使用带有内置 Gecode 6.1.1 的 minizinc,并且我希望最大化目标函数,其值远大于最大 int 32。32 位整数的最大值是 2147483646。虽然似乎没有太多信息与minizinc 参考文献中整数的最大值相关。然而,以下测试表明 Minizinc 使用 32 位整数。
测试非常简单,它只是尝试最大化 var int。
var int: maxInt;
constraint maxInt>0;
solve maximize maxInt;
output ["maxInt = \(maxInt)"];
Run Code Online (Sandbox Code Playgroud)
结果是
最大整数 = 2147483646
结果接近最大 int32 值,而且 miniZinc 似乎无法进一步“最大化”它。以下示例返回一个奇怪的错误。
var int: maxInt;
constraint maxInt>2147483646;
solve maximize maxInt;
output ["maxInt = \(maxInt)"];
Run Code Online (Sandbox Code Playgroud)
错误消息如下。该错误消息信息不多,但在尝试使用大于 2147483646 的数字时会显示。
错误:第 1 行中的整数文字无效。2 错误:语法错误,第 1 行出现意外的“,” 2 进程以非零退出代码 1 结束
我的问题如下:我可以在 minizinc 中使用 int64 位整数或任何其他大整数表示形式吗?如果可以,如何使用?(使用浮动不是一种选择)理想情况下,我想举一些例子来说明如何最大化某些东西
constraint maxLargeInt>2147483647;
Run Code Online (Sandbox Code Playgroud) MiniZinc 中的通道是什么?你能提供一个简单的例子来解释通灵吗?最后,什么是逆?
我正在尝试了解 MiniZincsgeost约束,这在 docs的打包约束部分中进行了描述。我正在尝试使用旋转来实现矩形的 2D 包装:所以我想将矩形放在给定长度和宽度的板上,但我很难理解预期的输入格式。
我有以下模型,我在其中读取了要放入nParts. nShapes是这些矩形可以采用的形状数。
include "globals.mzn";
int: nParts;
set of int: PARTS = 1..nParts;
int: nShapes;
set of int: SHAPES = 1..nShapes;
int: plateLength;
int: plateWidth;
set of int: LEN = 0..plateLength;
set of int: WID = 0..plateWidth;
int: k = 2;
set of int: DIM = 1..k;
array[SHAPES,DIM] of int: rect_size;
array[SHAPES,DIM] of 0..0: rect_offset;
array[PARTS] of set of SHAPES: shape;
array[PARTS,DIM] of …Run Code Online (Sandbox Code Playgroud) 我有一个 Minizinc 程序,用于为并网电池生成最佳充电/放电时间表,给定一组时间间隔价格。
我的程序有效(有点;有一些注意事项),但我的问题是关于两个“约束”语句,它们实际上只是赋值语句:
constraint forall(t in 2..T)(MW_SETPOINT[t-1] - SALE[t] = MW_SETPOINT[t]);
constraint forall(t in 1..T)(PROFIT[t] = SALE[t] * PRICE[t]);
Run Code Online (Sandbox Code Playgroud)
这些只是平均能量SALES是在三角洲MW_SETPOINT从t-1到1,并且PROFIT是SALE*PRICE每个间隔。因此,将它们声明为“约束”对我来说似乎违反直觉。但是我一直无法在不抛出语法错误的情况下将它们表述为赋值语句。
题:
constraints 中为数组赋值是在 Minizinc 中推荐的/惯用的方法吗?上下文的完整程序:
% PARAMS
int: MW_CAPACITY = 10;
array[int] of float: PRICE;
% DERIVED PARAMS
int: STARTING_MW = MW_CAPACITY div 2; % integer division
int: T = length(PRICE);
% DECISION VARIABLE - MW SETPOINT EACH INTERVAL
array[1..T] of var …Run Code Online (Sandbox Code Playgroud) 我一直在 MiniZinc 中使用一个简单的 n-queens 模型:
include "globals.mzn";
int: n_queens = 8;
array[1..n_queens] of var 1..n_queens: queens;
constraint alldifferent(queens);
constraint alldifferent(i in 1..n_queens) (queens[i] + i);
constraint alldifferent(i in 1..n_queens) (queens[i] - i);
solve satisfy;
Run Code Online (Sandbox Code Playgroud)
该MiniZinc手册中提到failures的“这是故障的叶节点的数目”。以下是运行模型后的统计数据:
%%%mzn-stat: initTime=0.000576
%%%mzn-stat: solveTime=0.000822
%%%mzn-stat: solutions=1
%%%mzn-stat: variables=24
%%%mzn-stat: propagators=19
%%%mzn-stat: propagations=1415
%%%mzn-stat: nodes=47
%%%mzn-stat: failures=22
%%%mzn-stat: restarts=0
%%%mzn-stat: peakDepth=5
%%%mzn-stat-end
Run Code Online (Sandbox Code Playgroud)
有 22 次失败。作为约束编程的初学者,我的理解是范式的整个目的是尽可能地修剪和避免叶节点。我特别困惑,因为搜索树的峰值深度报告为 5(不是 8)。
我对这些统计数据的解释正确吗?如果是,为什么模型中存在叶节点故障?我会通过尝试减少这些失败来创建更好的模型吗?
我正在 Minizinc 上对巨大的数据集执行聚类,但我的计算时间很长,我正在尝试减少它。为此,我想指定为变量尝试可能值的顺序。
例如,一个变量v作为一个域1..5,但我知道4比3更有可能,3比2更有可能,等等。在这种情况下,有没有办法让我说我想先尝试 4,然后是 3,然后是 2,等等?
minizinc ×10
optimization ×2
constraints ×1
gecode ×1
installation ×1
optimathsat ×1
or-tools ×1
parsing ×1
scheduler ×1
solver ×1