- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 node.js 模块“Governify CSP Tools”来解决 CSP 问题。按照我应该如何从 CSP 模型模式 (https://www.npmjs.com/package/governify-csp-tools) 定义数组的说明,我尝试了 JSON 中的多种表示形式,但仍然出现错误:
array: Ingredient_1= [30 , 30 , 30, 15, 15,15, 5 ,
5 , 5 , 1]; ^ Error: syntax error, unexpected ':', expecting [
我的javascript代码是:
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
});
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");
});
是否有任何解决方法我可以在 JSON 模式之外定义数组并稍后在 JSON 模式中再次调用它以在需要的地方进行迭代,例如:
"id": "C2",
"expression": "y=7 \\/ y=6 -> forall (i in occur)(Ingredient_1 [i]=30 )"
我尝试将其翻译成 JSON 的可执行文件 .mzn 表示是:
int: x = 0; % x-parameter
int: y = 7; % y-parameter
int: z = 0; % z-parameter
int: k = 4; % k-parameter
array[1..10] of int: Ingredient_1 = [30 , 30 , 30, 15, 15,15, 5 , 5 , 5 , 1]; % Ingredient_1-parameter
array [1..10] of int : Ingredient_2 = [3 , 7 , 12, 3 , 7 , 12, 3 , 7 , 12, 3 ]; % Ingredient_2-parameter
array [1..10] of int: Ingredient_3 = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]; % Ingredient_3-parameter
array[1..10] of int: Ingredient_4 = [0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]; % Ingredient_4-parameter
var set of 1..10: occur; % occur-variable
constraint x == 0 -> forall (i in occur) (Ingredient_4 [i]= 0); % C1-constraint
constraint y=7 \/ y=6 -> forall (i in occur)(Ingredient_1 [i]=30 ); % C2-constraint
constraint y==1 -> forall (i in occur)(Ingredient_1 [i]=0 ); % C3-constraint
constraint z==5 \/ z==6 \/ z==7 ->forall (i in occur)(Ingredient_4[i] !=0) ; % C4-constraint
constraint k==7 \/ k==6 -> forall (i in occur)(Ingredient_2 [i] =12); % C5-constraint
constraint k==5 -> forall (i in occur)(Ingredient_2 [i] =7); % C6-constraint
constraint k==4 \/ k==3 -> forall (i in occur)(Ingredient_2 [i] !=0); % C7-constraint
solve satisfy; % goal
问题是遵循 YAML 上表达的 JSON 模式,特别是:
title: 'CSP model JSON schema' type: 'object' properties:
parameters: type: 'array' items: type: 'object' properties: id:
来自 https://www.npmjs.com/package/governify-csp-tools ,我如何用 JSON 表示:
array[1..10] of int: Ingredient_1 = [30 , 30 , 30, 15, 15,15, 5 , 5 , 5 , 1];
最佳答案
虽然我对您正在使用的 javascript 库没有任何经验。似乎它正在使用字段 type
在生成的 MiniZinc 模型中没有任何转换。
正如您的 MiniZinc 模型所建议的,声明数组的正确方法是:
array[1..10] of int: Ingredient_1 = [30, 30, 30, 15, 15, 15, 5, 5, 5, 1];
但是,生成的 MiniZinc 模型包含:
array: Ingredient_1 = [30, 30, 30, 15, 15, 15, 5, 5, 5, 1];
这表明 type
字段不应包含 array
,但是array[1..10] of int
.
(其他JSON格式的数组可能会出现类似的问题)
关于javascript - MiniZinc CSP 转换为 JSON - 数组中的迭代解决方法 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52932706/
我想在 MiniZinc 中用相同的项目创建两个数组,不一定按相同的顺序。在这里,A0 中的每一项也应该在 A1 : array[1..3] of var int:A0; array[1..3] of
假设我想计算 {1,2,..100} 的 80 个元素子集的数量,使它们的总和为 3690。 我有以下模型: array[1..100] of var 0..1: b; constraint (sum
我看到 MiniZinc Handbook 中的各个地方都使用了 $ (主要在 Reference Manual 部分),但我一直找不到定义。有人可以向我解释一下吗?谢谢。 最佳答案 MiniZinc
在斑马谜题 ( http://rosettacode.org/wiki/Zebra_puzzle#MiniZinc ) 的解决方案中,有一个约束条件,规定其中一只宠物必须是斑马: var 1..5:
在斑马谜题 ( http://rosettacode.org/wiki/Zebra_puzzle#MiniZinc ) 的解决方案中,有一个约束条件,规定其中一只宠物必须是斑马: var 1..5:
我正在尝试解决 MiniZinc 中的一个练习,其中部分排序关系由二维数组给出: enum NODE = { A, B, C, D, E }; int : SOURCE = 1; int : TARG
我正在熟悉 MiniZinc 的基础知识。因此,借助 MiniZinc IDE,我编写了如下代码片段 solve satisfy; string: s1 = "hello"; string: s2 =
锌规范是这样说的: If no output item is present, the implementation should print all the global variables and
MiniZinc 中的 channel 是什么?你能提供一个简单的例子来解释 channel 吗?最后,什么是逆? 最佳答案 两者都用于建立两个数组之间的双向关系。 设 f 是一个数组,index_s
FlatZinc 文档说 只有非标谓词必须在 FlatZinc 模型的顶部声明: Predicates used in the model that are not standard FlatZinc
我有一个二维网格,其中某些单元格值会产生不同的分数,我想通过为单元格分配值来最大化分数。是否可以跟踪求解器在求解过程中尝试的每个网格?下面是模型的一个片段,只是为了演示这个想法。 int: i_cou
picat求解器 (v. 2.6#2) 指出示例模型 knights.mzn包含在 minizinc 存储库中,特此复制粘贴: % RUNS ON mzn20_fd % RUNS ON mzn-fzn
尝试学习 minizinc,但在完成示例之后,我是否可以确认,如果我想获得多个输出,或者有一种更“自然的 minizinc”方式来获得它,我实际上必须编写一些程序语言。 例如,假设我想让所有不同的数字
练习是: n个人想要拍一张合影。每个人都可以给出他或她旁边的偏好想要放置在照片上。要解决的问题是找到满足最大数量的放置位置偏好。 到目前为止我编写的代码: include "globals.mzn";
我正在尝试编写一个带有嵌套循环的输出语句,以及在外部级别的重要输出。如果 Minizinc 有一个顶级 for 命令,我会做类似的事情 for (f in Foo) ( output(["Foo:
我想检查 1 到 5 之间的哪个数字没有出现在数组组中,并将这个(或多个)数字放在另一个数组中。 g=2; set of int: GROUPS = 1..g; groups = [{1, 3}, {
问题 给定一个 MiniZinc 字符串数组: int: numStats; set of int: Stats = 1..numStats; array[Stats] of string: stat
我有一个变量,它应该只在特定条件下有一个值,所以我想它需要是一个可选变量。如果满足该条件,则可选变量应限制为集合的元素。 问题是,MiniZinc 似乎不喜欢可选变量和集合。 如何重写,使 MiniZ
我如何使用嵌套 for 循环(就像下面 java 所做的那样)在 Minizinc 中生成/填充数组? int[][] input1 = {{1,1,1}, {3,3,3}, {5,5,5} }; i
我正在使用 minizinc 和 gecode 以分布式方式解决最小化问题。我有多个分布式服务器,它们使用相同的输入来解决相同的模型,并且我希望所有服务器都能获得相同的解决方案。 问题是模型有多个解决
我是一名优秀的程序员,十分优秀!