【发布时间】:2018-11-11 09:16:46
【问题描述】:
我在 minizinc 中有一个脚本,它试图找到 int 集,但无法找到。问题陈述给出了一组 2 类特征,需要找到最小支持集,其长度应该小于一些 k,并且对于一些集合数组,它应该包含它们中的至少一个索引值。因此,假设解决方案是 {3,4,7} 并且集合数组(我们称之为 - atmostone) atmostone = [{1,2,3}, {4,5,6}, {7,8 ,9}] 所以解的交集和 atmostone 数组中的每个集合的长度必须正好为 1。
这些是我实现的约束,但错误是模型不一致。
include "globals.mzn";
include "alldifferent.mzn";
int: t; %number of attributes
int: k; %maximum size of support set
int: n; %number of positive instances
int: m; %number of negative instances
int: c; %number of atMostOne Constraints
array [1..n, 1..t] of 0..1: omegap;
array [1..m, 1..t] of 0..1: omegan;
array [int] of set of int: atMostOne;
set of int: K = 1..k;
set of int: T = 1..t;
var set of T: solution;
function array[int] of var opt int : set2array(var set of int: a) =
[i | i in a];
% constraint alldifferent(solution);
constraint length(set2array(solution)) <= k;
constraint forall(i in 1..length(atMostOne))(length(set2array(solution intersect atMostOne[i])) <= 1);
constraint forall(i in 1..n, j in 1..m)(not(omegap[i, fix(solution)] == omegan[j, fix(solution)]));
solve satisfy;
这是错误:
Compiling support_send.mzn
WARNING: model inconsistency detected
Running support_send.mzn
=====UNSATISFIABLE=====
% Top level failure!
Finished in 88msec
更新:
数据:
t=8; %number of attributes
k=3; %maximum size of support set
n=5; %number of positive instances
m=3; %number of negative instances
c=4; %number of atMostOne Constraints
omegap=[| 0,0,1,0,1,0,0,0 |
1,0,1,1,0,0,0,1|
0,1,0,1,0,0,1,1|
0,1,1,0,1,1,0,1|
0,0,1,0,1,1,1,1
|];
omegan=[| 1,1,0,0,1,0,1,1|
0,1,0,0,1,1,0,0|
1,0,0,1,1,0,0,1
|];
atMostOne =
[{1,2,3},
{4,5,6},
{3,5},
{7,8}];
任何帮助将不胜感激。
谢谢。
【问题讨论】:
-
您能分享确切的数据定义吗? (dzn 文件)
-
@Dekker1 用数据更新了问题。
-
您的数据现在不一致,数据文件中声明的任何内容都没有声明,并且 T 未定义,与您的模型。能否请您完整提供两者,以便我们运行您正在运行的程序?
-
@Dekker1 更新了完整代码。
标签: optimization constraint-programming minizinc