저는 MiniZinc를 배우기 시작했습니다. 코드를 보지 않고 MiniZinc Tutorial에서 제공되는 laplace.mzn 예제를 완성하려고합니다. 아래의 코드 블록 1에 나와있는 원래의 시도는 정확한 대답을 제공합니다. 나는 show_float() 함수에서 6의 하드 코드 된 값을 만들어서 출력 진술을 일반화하려고 노력했다. 출력의 모든 float은 6 자리 숫자로 오른쪽 정렬되어야하고 (즉, t와 . 그 기지에서 출력 폭은MiniZinc 최대 var float의 2D 배열에서 값
내 첫 번째 시도는 코드 블록 2의 문을 추가했다, 그러나 나는 다음과 같은 오류 접수 : MiniZinc : 평가 오류 :
laplace.mzn : 28 : 변수에
을 'm' '최대'
/home/str/MiniZinc/share/minizinc/std/builtins.mzn:278 통화
에 대한 선언 :하자 발현 0
/home/str/MiniZinc/share/minizinc/std/builtins.mzn:281 : 전화 'max_t'
/home/str/MiniZinc/share/minizinc/std/builtins.mzn:2020에서
:
경우 - 당시 다른 표현
/home/str/MiniZinc/share/minizinc/std/builtins.mzn:2023에서 :하자 발현
/홈/STR/miniZinc/주/minizinc/표준/내장 명령 .mzn : 2025 :
전화 'array_float_maximum'
/home/str/MiniZinc/share/minizinc/linear/redefinitions-2.0.mzn:16에서 : IF-에서
당시 다른 표현
/home/str/MiniZinc/share/minizinc/linear/redefinitions-2.0.mzn:19 : 'array_float_minimum_I'
/홈/STR/MiniZinc/주/minizinc/선형/재정의 통화에서
하자 발현
/home/str/MiniZinc/share/minizinc/linear/redefinitions.mzn:110 : .mzn 108
와 I = 1 호 "UB"
가 경계를 결정할 수있는
그렇다면 나는 그것이 어떻게 느껴지는지 행복하지 않았지만
MiniZinc : 평가 오류 :
/home/str/MiniZinc/share/minizinc/linear/redefs_lin_reifs.mzn:319 : D, I는 다음과 같은 오류가 발생한 코드 블록 (3), 시도
의 경우 해당 시점을- 다른 표현
/home/str/MiniZinc/share/minizinc/linear/redefs_lin_reifs.mzn:321 : 전화 'UB'
가 경계
에서 최대 값을 구하는 방법에 대한 제안을 확인할 수 없습니다에
제약 조건 문제가 만족 된 후 't'? 미리 감사드립니다.
코드 블록 1 :
int: w = 5;
int: h = 5;
array[1..h,1..w] of var float: t;
float: top = 100.0;
float: bottom = 0.0;
float: left = 0.0;
float: right = 0.0;
float: corners = 0.0;
% Top row all the same except corners
constraint forall(c in 2..w-1)(t[1,c] = top);
% Bottom row all the same except corners
constraint forall(c in 2..w-1)(t[h,c] = bottom);
% First column all the same except corners
constraint forall(r in 2..h-1)(t[r,1] = left);
% Last column all the same except corners
constraint forall(r in 2..h-1)(t[r,w] = right);
% The four corners must be the same value
constraint t[1,1] = corners /\ t[1,1] = t[1,w] /\ t[1,w] = t[h,w] /\ t[h,w] = t[h,1];
constraint forall(r in 2..h-1, c in 2..w-1)(4*t[r,c] = t[r-1,c] + t[r+1,c] + t[r,c-1] + t[r,c+1]);
solve satisfy;
output[ show_float(6,2,t[r,c]) ++
if c = h then "\n" else " " endif
| r in 1..h, c in 1..w ];
코드 블록 2 :
var float: m = max(r in 1..h, c in 1..w)(t[r,c]);
코드 블록 3 :
% Width of temperature grid
int: w = 5;
% Height of temperature grid
int: h = 5;
array[1..h,1..w] of var float: t;
% Temperature in the top row, bottom row, left row, right row, and corners
float: top = 100.0;
float: bottom = 0.0;
float: left = 0.0;
float: right = 0.0;
float: corners = 0.0;
% Top row all the same except corners
constraint forall(c in 2..w-1)(t[1,c] = top);
% Bottom row all the same except corners
constraint forall(c in 2..w-1)(t[h,c] = bottom);
% First column all the same except corners
constraint forall(r in 2..h-1)(t[r,1] = left);
% Last column all the same except corners
constraint forall(r in 2..h-1)(t[r,w] = right);
% The four corners must be the same value
constraint t[1,1] = corners /\ t[1,1] = t[1,w] /\ t[1,w] = t[h,w] /\ t[h,w] = t[h,1];
constraint forall(r in 2..h-1, c in 2..w-1)(4*t[r,c] = t[r-1,c] + t[r+1,c] + t[r,c-1] + t[r,c+1]);
% Get the maximum value in t
var float: m;
constraint forall(r in 1..h, c in 1..w)(m >= t[r,c]);
constraint exists(r in 1..h, c in 1..w)(m = t[r,c]);
solve maximize m;
% Wish to replace the value six in the next line with m + 3, where the 3 represents
% character for the 2 digits to the right of a decimal point and 1 character for the
% decimal point
output[ show_float(6,2,t[r,c]) ++
if c = h then "\n" else " " endif
| r in 1..h, c in 1..w ];