Title: FunctionConstraints are not respected by solution when added as a series of pairwise constraints between variables. · Issue #102 · python-constraint/python-constraint · GitHub
Open Graph Title: FunctionConstraints are not respected by solution when added as a series of pairwise constraints between variables. · Issue #102 · python-constraint/python-constraint
X Title: FunctionConstraints are not respected by solution when added as a series of pairwise constraints between variables. · Issue #102 · python-constraint/python-constraint
Description: Hi, it seems the solution returned by this simple example violates the added constraints. I may have implemented it wrong or missed something about how constraints are handled (conjunction vs disjunction?) but it appears that the constra...
Open Graph Description: Hi, it seems the solution returned by this simple example violates the added constraints. I may have implemented it wrong or missed something about how constraints are handled (conjunction vs disju...
X Description: Hi, it seems the solution returned by this simple example violates the added constraints. I may have implemented it wrong or missed something about how constraints are handled (conjunction vs disju...
Opengraph URL: https://github.com/python-constraint/python-constraint/issues/102
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"FunctionConstraints are not respected by solution when added as a series of pairwise constraints between variables.","articleBody":"\nHi, it seems the solution returned by this simple example violates the added constraints.\nI may have implemented it wrong or missed something about how constraints are handled (conjunction vs disjunction?) but it appears that the constraints provided pairwise, aren't chained together properly to enforce a globally consistent solution. I apologise if this is as designed, but I couldn't find any hints in the documentation that this behaviour is to be expected.\n\nPython version: 3.9.7\nOS: Windows 10\npython-constraint2 release: 2.4.0 (installed through pip)\n\n```\nfrom constraint import Problem\nproblem = Problem()\ndomain = ['a', 'b']\n\ngrid_size = 4\nnum_tiles = grid_size**2\ntile_indices = range(num_tiles)\nproblem.addVariables(tile_indices, domain)\n\n# enforces inequality between horizontal neighbours\nfor row in range(grid_size):\n for col in range(grid_size-1):\n idx = row*grid_size + col\n idx_right = row*grid_size + col+1\n problem.addConstraint(lambda r, c: c != r, [idx_right, idx])\n\n# enforces inequality between vertical neighbours\nfor row in range(grid_size-1):\n for col in range(grid_size):\n idx = row*grid_size + col\n idx_down = (row+1)*grid_size + col\n problem.addConstraint(lambda d, c: c != d, [idx_down, idx])\n\nsolution = problem.getSolution()\n\n# print solution\nif solution:\n for row in range(grid_size):\n for col in range(grid_size):\n idx = row*grid_size + col\n if col == grid_size-1: \n print(f\"{list(solution.values())[idx]}\")\n else:\n # don't print newline unless at edge\n print(f\"{list(solution.values())[idx]}\", end='')\n \n[ds, cs,cvs] = problem._getArgs()\nprint(ds)\nprint(cs)\nprint(cvs)\n\n```\nI would expect the solution to be some form of 4x4 checker-board pattern of 'a' and 'b' but instead I get\n\n```\nbaab\nabab\nbaba\nbaab\n```\nwhich obviously has a's and b's appearing next to each other in both rows and columns.\n\nprinting the constraints out shows that there is a constraint defined between 12 and 8 (which should be the two b's at the start of the last and second-to-last rows)\n\n12: [(\u003cconstraint.constraints.FunctionConstraint object at 0x000001AB812E0B50\u003e, [13, 12]), (\u003cconstraint.constraints.FunctionConstraint object at 0x000001AB812E0F70\u003e, [12, 8])]","author":{"url":"https://github.com/dcanelhas","@type":"Person","name":"dcanelhas"},"datePublished":"2025-07-23T11:26:22.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/102/python-constraint/issues/102"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:75a5f8a8-b286-0b9e-8f22-b145f6749774 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CE7A:1E201A:28BC68:37C00D:696E6F00 |
| html-safe-nonce | 78a6151ad85a3c6c3f1068f7372fa0198d30a9ea1a83381fff4d0d1ec4c885a4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTdBOjFFMjAxQToyOEJDNjg6MzdDMDBEOjY5NkU2RjAwIiwidmlzaXRvcl9pZCI6IjExNzE3ODQ5MDM5NTU0NzYyMjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c5d56f470e7e97a7339e82a2f09c1b590fcbc9b860f6fa329462c199ed32b07b |
| hovercard-subject-tag | issue:3255987171 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-constraint/python-constraint/102/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0ccabd25af64b1cc9be8dca288e52b2777739e7a253af2a4c1fd8a8bc30591f6/python-constraint/python-constraint/issues/102 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0ccabd25af64b1cc9be8dca288e52b2777739e7a253af2a4c1fd8a8bc30591f6/python-constraint/python-constraint/issues/102 |
| og:image:alt | Hi, it seems the solution returned by this simple example violates the added constraints. I may have implemented it wrong or missed something about how constraints are handled (conjunction vs disju... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dcanelhas |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd24262d9e4947a6c63df018b01e9a6da49caaf8259148a56a04b665d15d66b3 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-constraint/python-constraint git https://github.com/python-constraint/python-constraint.git |
| octolytics-dimension-user_id | 14961635 |
| octolytics-dimension-user_login | python-constraint |
| octolytics-dimension-repository_id | 43628779 |
| octolytics-dimension-repository_nwo | python-constraint/python-constraint |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 43628779 |
| octolytics-dimension-repository_network_root_nwo | python-constraint/python-constraint |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 307ab96ec5f21762ff6c530a60b1ef6b1e74dd5a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width