# governify-csp-tools - An example with array parameter

(tina) #1

Hi,
i’ m using the package

governify-csp-tools

to run a CSP problem in node.
I have trouble though to represent the array parameters although I have followed the CSP model schema.
The .mzn code which runs successfuly in MiniZinc is :

``````int: x;
int: y;
int: z;
int: k;

array[1..50] of {0,1,5,15,30}: Ingredient_1=[30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1,	1,	1,	30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1,	1,	1,	30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1,	1,	1,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0	];

array[1..50] of {0,3,7,12}: Ingredient_2=[3 ,	7 ,	12,	3 ,	7 ,	12,	3 ,	7 ,	12,	3 ,	7 ,	12,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	3 ,	3 ,	3 ,	7 ,	7 ,	7 ,	12,	12,	12,	3 ,	3 ,	3 ,	7 ,	7 ];

array[1..50] of {0,3,6,1000}: Ingredient_3= [0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	0   ,	0   ,	0   ,	0   ,	0];

array[1..50] of {0,3,6,1000}: Ingredient_4=[0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6];

%decision variable%
var set of 1..50 : occur;

%c1
constraint x=0-> forall (i in occur) (Ingredient_4 [i]= 0);
%c2
constraint y=7 \/ y=6 -> forall (i in occur)(Ingredient_1 [i]=30 );
%c3
constraint y=1 -> forall (i in occur)(Ingredient_1 [i]=0 ) ;
%c4 z in 5..7
constraint z =5 \/ z=6\/ z=7  ->  forall (i in occur)(Ingredient_4[i] !=0) ;
%c5
constraint k=7 \/ k=6  -> forall (i in occur)(Ingredient_2 [i] =12);
%c6
constraint k=5 -> forall (i in occur)(Ingredient_2 [i] =7);
%c7
constraint k=4 \/ k=3  -> forall (i in occur)(Ingredient_2 [i] !=0);

solve satisfy;

output ["product ids:" ++show(occur) ++"\n"

++"Ingredient_1:" ++show(i in occur) (Ingredient_1[i])++"\n"
++"Ingredient_2:" ++show(i in occur) (Ingredient_2[i])++"\n"
++"Ingredient_3:" ++show(i in occur) (Ingredient_3[i])++"\n"
++"Ingredient_4:" ++show(i in occur) (Ingredient_4[i])++"\n"
++"Total number of products:"++ show(card(occur))++"\n"
];

%Data Input

y =7;
x=0;
z=0;
k=4;
``````

and the cspModel I constructed in node .js file:

var cspModel = {
“parameters”:[

``````    {
"id":"x",
"type":"int",
"value":"0"
},
{
"id":"y",
"type":"int",
"value":"7"
},
{
"id":"z",
"type":"int",
"value":"0"
},
{
"id":"k",
"type":"int",
"value":"4"
},
{
"id":"Ingredient_1",
"type":"array",
"items":[30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1,	1,	1,	30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1,	1,	1,	30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1,	1,	1,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0	]
},
{
"id":"Ingredient_2",
"type":"array",
"items":[3 ,	7 ,	12,	3 ,	7 ,	12,	3 ,	7 ,	12,	3 ,	7 ,	12,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	0 ,	3 ,	3 ,	3 ,	7 ,	7 ,	7 ,	12,	12,	12,	3 ,	3 ,	3 ,	7 ,	7 ]
},
{
"id":"Ingredient_3",
"type":"array",
"items":[0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	0   ,	0   ,	0   ,	0   ,	0]
},
{
"id":"Ingredient_4",
"type":"array",
"items":[0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	3   ,	6   ,	1000,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	3   ,	6   ,	1000,	3   ,	6]
},
],
"variables": [
{
"id": "occur",
"type": "int",
"range": {
"min": "1",
"max": "50"
}

}

],
"constraints": [
{
"id": "C1",
"expression": "x == 0 -> forall (items in occur) (Ingredient_4 [items]= 0)"
},
{
"id": "C2",
"expression": "y=7 \\/ y=6 -> forall (items in occur)(Ingredient_1 [items]=30 )"
},
{
"id": "C3",
"expression": "y==1 -> forall (items in occur)(Ingredient_1 [items]=0 )"
},
{
"id": "C4",
"expression": "z==5 \\/ z==6 \\/ z==7  ->forall (items in occur)(Ingredient_4[items] !=0) "
},
{
"id": "C5",
"expression": "k==7 \\/ k==6 -> forall (items in occur)(Ingredient_2 [items] =12)"
},
{
"id": "C6",
"expression": "k==5 -> forall (items in occur)(Ingredient_2 [items] =7)"
},
{
"id": "C7",
"expression": "k==4 \\/ k==3  -> forall (items in occur)(Ingredient_2 [items] !=0)"
},
],
"goal": "satisfy"
};
``````

when i ran it I get the error:

array: Ingredient_1 = undefined; % Ingredient_1-parameter
^
Error: syntax error, unexpected ‘:’, expecting [

can somebody give me an example of how I should define the arrays into the csp Model?

(system) #2

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.