governify-csp-tools- An example of arrays Minizinc to JSON


(tina) #1

using the library and the definiiton on JSON for the package governify-csp-tools:

I have trouble in representing an .mzn file into JSON, i get

array: Ingredient_1 = [30 , 30 , 30, 15, 15,15, 5 , 5 , 5 , 1]; % Ingredient_1-parameter
^
Error: syntax error, unexpected ‘:’, expecting [

can you provide an example of how an array should be represented?
I have tried the below code with multiple mixes:

var Reasoner = require("governify-csp-tools").Reasoner;



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",
         
          "value":"[30 ,	30 ,	30,	15,	15,15,	5 ,	5 ,	5 ,	1]",
      },
      {
          "id":"Ingredient_2",
          "type":"array",
          "value":"[3 ,	7 ,	12,	3 ,	7 ,	12,	3 ,	7 ,	12,	3 ]"
      },
      {
          "id":"Ingredient_3",
          "type":"array",
          
          "value":"[0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ]"
      },
      {
          "id":"Ingredient_4",
          "type":"array",
          "value":"[0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ,	0   ]"
      },
      ],
    "variables": [
      {
        "id": "occur",
        "type": "int",
        "range": {
          "min": "1",
          "max": "10"
        }
  
      }
      
    ],
    "constraints": [
      {
        "id": "C1",
        "expression": "x == 0 -> forall (i in occur) (Ingredient_4 [i]= 0)"
      },
      {
        "id": "C2",
        "expression": "y=7 \\/ y=6 -> forall (i in occur)(Ingredient_1 [i]=30 )"
      },
      {
          "id": "C3",
          "expression": "y==1 -> forall (i in occur)(Ingredient_1 [i]=0 )"
        },
      {
          "id": "C4",
          "expression": "z==5 \\/ z==6 \\/ z==7  ->forall (i in occur)(Ingredient_4[i] !=0) "
      },
      {
          "id": "C5",
          "expression": "k==7 \\/ k==6 -> forall (i in occur)(Ingredient_2 [i] =12)"
      },
      {
          "id": "C6",
          "expression": "k==5 -> forall (i in occur)(Ingredient_2 [i] =7)"
      },
      {
          "id": "C7",
          "expression": "k==4 \\/ k==3  -> forall (i in occur)(Ingredient_2 [i] !=0)"
      },
    ],
    "goal": "satisfy"
  };
   
  // Configure the CSP reasoner
  var reasoner = new Reasoner({
      type: 'local', // type value also can be 'api' or 'docker'
      folder: 'csp_files' // name of the folder which stores .mzn, .fzn and .ozn temporary files
      
  });
  //var Ingredient_1=[30 ,	30 ,	30 ,	15,	15,	15,	5 ,	5 ,	5 ,	1]

  console.log("solving model");
  // Solve CSP
  reasoner.solve(cspModel, (err, stdout, stderr, isSatisfiable) => {
  
      if (err) {
          // manage error
          console.log("model error");
          
      } else {
          
          console.log(stdout);
          console.log(isSatisfiable);
        
      }
      console.log("model solved");
    
  });

(system) #2

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