Issue
I have the following code:
output["\(w) \(l)\n\(n)\n"] ++ [if rotation[i] then "\(x[i]) \(y[i]) \(p_x[i]) \(p_y[i]) R\n" else "\(x[i]) \(y[i]) \(p_x[i]) \(p_y[i])\n" endif |i in CIRCUITS];
My purpose is to print each row and the vaue "R" whether rotation[i] is true, false otherwise. For instance:
w l
n
x[1] y[1] p_x[1] p_y[1] "R"
x[2] y[2] p_x[2] p_y[2]
In this example rotation[1] is true and rotation[2] is false
Solution
Your sample MiniZinc code was almost there. The important change you will have to make if to force the "rotation" variable to take its "solution value" using the "fix" builtin function.
output ["\(w) \(l)\n\(n)\n"]
++ ["\(x[i]) \(y[i]) \(p_x[i]) \(p_y[i])"
++ if fix(rotation[i]) then " R" else "" endif
++ "\n"
| i in index_set(rotation)];
Additionally, I would suggest trying to make the conditional part as small as possible to improve readability, as incorporated in the above code fragment.
Answered By - Dekker1 Answer Checked By - Candace Johnson (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.