2017-03-16 2 views
1

배열을 사용하기 위해 튜토리얼의 호주 프로그램을 변환하려고합니다.문자 그대로 출력하지 않고 어떻게 MiniZinc 출력이 이스케이프를 해석하도록 할 수 있습니까?

나는 지혜로, 출력에 문제가있어 :

% Coloring Australia using nc colors 

int: nc = 3; % number of colors 
int: ns = 7; % number of states 
array[1..nc] of string:  colors = ["red", "green", "blue"]; 
array[1..ns] of string:  states = ["wa","nt","sa","q","nsw","v","t"]; 
array[1..ns] of var 1..ns: indices = [1,2,3,4,5,6,7]; 

array[1..ns] of var 1..nc: color; % computed color for each state 

% I want to use the name as a mnemonic for the index of the state 
var int: wa=1; % I know of no alternative to the brute force method 
var int: nt=2; var int: sa=3; var int: q=4; 
var int: nsw=5; var int: v=6; var int: t=7; 

constraint color[wa] != color[nt]; % abutting states 
constraint color[wa] != color[sa]; 
constraint color[nt] != color[sa]; 
constraint color[nt] != color[q]; 
constraint color[sa] != color[q]; 
constraint color[sa] != color[nsw]; 
constraint color[sa] != color[v]; 
constraint color[q] != color[nsw]; 
constraint color[v] != color[nsw]; 

solve satisfy; 

/* 
    I want a loop to print it out like this: 
"wa" = "blue" 
"nt" = "green" 
... 
*/ 

output [ 
    show(["\n\(states[j]) = \(colors[color[j]])" | j in indices]) 
]; 
/* prints 

["\n\"wa\" = \"blue\"", "\n\"nt\" = \"green\"", "\n\"sa\" = \"red\"",  "\n\"q\" = \"blue\"", "\n\"nsw\" = \"green\"", "\n\"v\" = \"blue\"", "\n\"t\" = \"red\""] 
*/ 

가 어떻게 쇼의 \ n은 새로운 라인을 만들고, 상수에 따옴표를 벗어날 수를 얻을 수 있나요? 작은 따옴표 대신 perl 이중 따옴표 같이?

그리고/또는 따옴표없이 상수를 정의 할 수있는 방법이 있습니까? 펄 펄처럼?

답변

3

코드에서 약간의 실수를했습니다. show는 변수를 출력하는 데 사용됩니다.

output["this is variable x:" ++ show(x)] 

\(x) 즉, 포맷 된 문자열로 지정된 배열을 인쇄합니다 "++show(x)++"

output 문 자체에 대한 속기는 다음과 같은 것이 사용된다. 이 형식화 된 문자열은 예상대로 이스케이프 된 문자를 포함 할 수 있습니다. 따라서 모델에 맞는 올바른 출력 문은 다음과 같습니다.

output ["\n\(states[j]) = \(colors[color[j]])" | j in indices];