Skip to content

Instantly share code, notes, and snippets.

@Alexander-Schiendorfer
Created November 10, 2015 12:53
Show Gist options
  • Save Alexander-Schiendorfer/4b98df990cf03bd9f4af to your computer and use it in GitHub Desktop.
Save Alexander-Schiendorfer/4b98df990cf03bd9f4af to your computer and use it in GitHub Desktop.
% a very minimal example to provoke isa: nullptr bug
% ---------------------------------
set of int: range = 1..5;
var set of range: x;
predicate onlyEvens(var set of range: y) =
(
forall(r in y) (r mod 2 = 0)
);
constraint onlyEvens(x);
solve :: set_search([x], input_order, indomain_max, complete)
satisfy;
@Alexander-Schiendorfer
Copy link
Author

This one produces the correct sequence of solutions of sets between 1..5 and {} with only even integers.

@Alexander-Schiendorfer
Copy link
Author

Alexander-Schiendorfer commented Feb 13, 2017

include "classic_o.mzn"; % output of minibrass
include "soft_constraints/pvs_gen_search.mzn"; % for generic branch and bound

% the basic, "classic" CSP 
set of int: NURSES = 1..3;
int: day = 1; int: night = 2; int:off = 3;
set of int: SHIFTS = {day,night,off};

array[NURSES] of var SHIFTS: n;

% additional hard constraints would be here 

solve 
:: pvsSearchHeuristic
search pvs_BAB();

output ["n = \(n)"] ++ 
       [ "\nValuations:  topLevelObjective = \(topLevelObjective)\n"];

that is accompanied by this MiniBrass model

type ConstraintPreferences = PVSType<bool, set of 1..nScs> = 
  params { 
    array[int, 1..2] of 1..nScs: crEdges;
    bool: useSPD;
  } in 
  instantiates with "soft_constraints/mbr_types/cr_type.mzn" {
    times -> link_invert_booleans;
    is_worse -> is_worse_cr;
    top -> {};
};
    

PVS: cr1 = new ConstraintPreferences("cr1") {
   soft-constraint c1: 'sum(i in NURSES)(bool2int(n[i] = night)) = 2';
   soft-constraint c2: 'n[2] in {day,off}';
   soft-constraint c3: 'n[3] = off';
   
   crEdges : '[| mbr.c2, mbr.c1 | mbr.c3, mbr.c1 |]';
   useSPD: 'true' ;
}; 

solve cr1;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment