Skip to main content

Adding 'assumed' variable values

Awaiting user input

Comments

3 comments

  • Ryuta Tamura
    • Gurobi Staff

    Hi,
    From the perspective of your formulation, the results obtained are natural. The objective function is to maximize s1 + s2, which drives each variable toward 1, and (s1, s2) = (1, 1) satisfies the two constraints (s1 <= s2, s2 <= s1). Because both lead to 1≤1. In fact, assuming s1 and s2 were neighbors in your problem, they appear to satisfy the following condition by becoming 1 with each other.

    I have a grid of binary variables and want these variables to be 0 unless at least one neighbor is 1. 

    There might be other conditions that are missing. Could you provide a little more detail?

    Thanks,
    Ryuta

    0
  • Sophieke van Luenen
    • First Comment
    • Gurobi-versary
    • First Question

    Hi Ryuta, thanks for the reply!

     

    The larger problem that I am modelling is about a grid of tiles which may be covered or not covered, according to a number of constraints. I successfully modeled all constraints but one: all uncovered tiles must be on an orthogonal path (one can reach any uncovered tile from any other uncovered tiles by only visiting orthogonally adjacent uncovered tiles). 

     

    As such I now have grid 1 of binary variables which handles all the other rules, and grid 2 of binary variables for the pathfinding constraint. The idea there being that grid 2 represents all tiles on the path. We start with one tile set to 1 on grid 2. All variables that are covered in grid 1 are always set to 0 on grid 2, and variables on grid 2 can only be set to 1 if they are adjacent to a variable that is already set to 1. 

     

    The idea being here that the path on grid 2 will propagate to orthogonally adjacent uncovered tiles, unable to pass through covered tiles. If we request the number of variables on the path to be maximised, or indeed require it to equal the number of tiles not covered in grid 1, we ensure that all uncovered tiles are orthogonally adjacent (if such a solution exists).

    Now this made me test these circular constraints that I made above, where s1 ≤ s2 and s2 ≤ s1, and hence the question. I know that this method works in some other constraint programming frameworks, so hence the question on whether it would also be possible in Gurobi. 

     

    I look forward to hearing from you!

     

    Sophieke

    0
  • Ryuta Tamura
    • Gurobi Staff

    Hi, 
    In MILP, s1 ≤ s2 and s2 ≤ s1 imply s1 ≤ s2 ≤ s1, which is equivalent to s1 = s2. Therefore, this expression is a simple equality. Perhaps you are misunderstanding the Start attribute. This is simply the initial solution; Gurobi will discover the optimal solution with the best objective value, (s1, s2) = (1, 1), and report it as such. 

    Back to your problem, if you require the connectivity of uncovered tiles, you must express that as a constraint. To ensure connectivity, you can use flow formulation, for example. I will outline the direction for formalization:

    • First, suppose a flow of g from super-source. Here, g is equal to the number of uncovered tiles.
    • One of the uncovered tiles receives a g flow from the super-source.
    • Flow can only pass between orthogonally adjacent uncovered tiles, and each tile traversed consumes exactly one unit of flow.
    • The flow entering and exiting the tile satisfies the Flow conservation law.

    To consume all g flow, all uncovered tiles must be connected, and this will fulfill what you want to do. Can this be applied to your model?

    Thanks,
    Ryuta

    0

Please sign in to leave a comment.