PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

[FIXED] How can I write conditional expression in output of a minizinc program?

 August 16, 2022     conditional-statements, minizinc, output     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing