MiniZinc find the set of int











up vote
0
down vote

favorite












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.










share|improve this question
























  • Could you share the exact data definitions? (dzn file)
    – Dekker1
    Nov 11 at 23:26










  • @Dekker1 updated the question with the data.
    – user10635606
    Nov 12 at 2: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 at 6:18










  • @Dekker1 updated complete code.
    – user10635606
    Nov 12 at 15:48















up vote
0
down vote

favorite












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.










share|improve this question
























  • Could you share the exact data definitions? (dzn file)
    – Dekker1
    Nov 11 at 23:26










  • @Dekker1 updated the question with the data.
    – user10635606
    Nov 12 at 2: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 at 6:18










  • @Dekker1 updated complete code.
    – user10635606
    Nov 12 at 15:48













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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.










share|improve this question















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.







optimization constraint-programming minizinc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 at 15:47

























asked Nov 11 at 9:16







user10635606



















  • Could you share the exact data definitions? (dzn file)
    – Dekker1
    Nov 11 at 23:26










  • @Dekker1 updated the question with the data.
    – user10635606
    Nov 12 at 2: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 at 6:18










  • @Dekker1 updated complete code.
    – user10635606
    Nov 12 at 15:48


















  • Could you share the exact data definitions? (dzn file)
    – Dekker1
    Nov 11 at 23:26










  • @Dekker1 updated the question with the data.
    – user10635606
    Nov 12 at 2: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 at 6:18










  • @Dekker1 updated complete code.
    – user10635606
    Nov 12 at 15:48
















Could you share the exact data definitions? (dzn file)
– Dekker1
Nov 11 at 23:26




Could you share the exact data definitions? (dzn file)
– Dekker1
Nov 11 at 23:26












@Dekker1 updated the question with the data.
– user10635606
Nov 12 at 2:33




@Dekker1 updated the question with the data.
– user10635606
Nov 12 at 2: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 at 6:18




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 at 6:18












@Dekker1 updated complete code.
– user10635606
Nov 12 at 15:48




@Dekker1 updated complete code.
– user10635606
Nov 12 at 15:48












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










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.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247327%2fminizinc-find-the-set-of-int%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown
























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    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.






    share|improve this answer

























      up vote
      1
      down vote



      accepted










      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.






      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 at 9:00









        Dekker1

        2,1161319




        2,1161319






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247327%2fminizinc-find-the-set-of-int%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues