0

I have a script in minizinc that tries to find the set of int, but is unable to do so. The problem statement is given a set of 2 class features, minimal support set needs to be found with constraints that its length should be less than some k, and with some array of set it should contain atleast one of the index value from them. So, suppose, that the solution is {3,4,7} and the array of set (let's call it - atmostone) atmostone = [{1,2,3}, {4,5,6}, {7,8,9}] so the intersection of the solution and each of the set from atmostone array must be of exactly length one.

These are the constraints I implemented, but the error is of model inconsistency.

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;

This is the error:

Compiling support_send.mzn

  WARNING: model inconsistency detected
Running support_send.mzn
=====UNSATISFIABLE=====
% Top level failure!
Finished in 88msec

Update:

The data:

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}];

Any help would be appreciated.

Thank You.

  • Could you share the exact data definitions? (dzn file) – Dekker1 Nov 11 '18 at 23:26
  • @Dekker1 updated the question with the data. –  Nov 12 '18 at 02:33
  • Your data is now inconsistent there is no declaration for anything declared in the data file and T is undefined, with your model. Could you please provide both in full so we can run what you are running? – Dekker1 Nov 12 '18 at 06:18
  • @Dekker1 updated complete code. –  Nov 12 '18 at 15:48

1 Answers1

3

The problems in your model stem from your set variable solutions.

The first problem is caused by the set2array function. You might think that this returns an array with the integers that are located in your array; however, that is not true. Instead it returns an array of optional integers. This means that all values that are possible in your set are stored in the array, but some of them might just be marked absent. In this case it is almost the same as having an array of boolean variables, that just say if a value is located in the set or not.

Note that the constraint length(set2array(solution)) <= k is impossible to satisfy. Because solution has more possible than k the length of the array will always be bigger. The constraint you probably want to enforce is card(solution) <= k. The function card(X) return the cardinality/size of a set. The same problem can be found in the second constraint.

Your final constraint has a different problem: it contains the expression fix(solution). In the context of your model you cannot write this because won't be fixed at compilation time. The expression also evaluates into a set of int. Although you can use sets to access an array, array slicing, it is currently not allowed with variables sets. I would suggest trying to find a different formulation for this constraint. (Because I cannot figure out what it is supposed to do, I'm afraid I cannot suggest anything)

As a final note, the commented out constraint, alldifferent(solution), is unnecessary. Because solution is a set, it is guaranteed to contain values only once.

Dekker1
  • 5,565
  • 25
  • 33