Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Combinatorial optimization #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
themmes opened this issue Oct 11, 2018 · 0 comments
Open

Combinatorial optimization #42

themmes opened this issue Oct 11, 2018 · 0 comments
Labels

Comments

@themmes
Copy link

themmes commented Oct 11, 2018

Hi there, thanks for sharing this library, it seems potentially very useful for the problem I try to solve. First of I am not too sure if the library is actually made for this type of problem, but I assume it is.

I created a set of polygons based on bag of plane intersection.

schermafbeelding 2018-10-11 om 16 50 39

Now I try to create the following manifold by combinatorial optimization.

schermafbeelding 2018-10-11 om 16 50 51

The idea was to use python-constraint to generate possible solutions and select the best fitting by optimization of some weights on each polygon with scipy.optimize.

So far I came up with this:

import constraint
problem = constraint.Problem()
problem.addVariables(range(len(polygons)), [True, False])

for idx, polygon in enumerate(polygons):
    edge_adjacent_polygons = [polygon[a][b]['polygon'] for a, b in polygon.edges()]
    if all([len(adjacent_polygons) > 2 for adjacent_polygons in edge_adjacent_polygons]):
        for adjacent_polygons in edge_adjacent_polygons:
            problem.addConstraint(lambda *adjacent_polygons: sum(adjacent_polygons) == 2, adjacent_polygons)
    elif any([len(adjacent_polygons) == 2 for adjacent_polygons in edge_adjacent_polygons]) & \
        all([len(adjacent_polygons) >= 2 for adjacent_polygons in edge_adjacent_polygons]):
        problem.addConstraint(lambda idx: idx == True, [idx])
    else:
        problem.addConstraint(lambda idx: idx == False, [idx])

However, so far this generates 0 solutions in problem.getSolutions(). I suspect I have misunderstood how I could add the combinatorial constraints to the model. It is important polygons are chosen in such a way every edge is incident to two (and only two) polygons (polygon[a][b]['polygon'] points to a list of polygon ids the edge is incident to).

I really hope you can help me, I understand programming solvers like this is really hard and programming a custom one for my project seems beyond the scope. I think your solver is the only one that gets at least close to what I need to solve this.

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants