TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Using Monads in C++ to Solve Constraints: 3. The Tale of Two Monads

28 pointsby andrzejszabout 10 years ago

1 comment

graycatabout 10 years ago
For the sample <i>constraint satisfaction</i> problem<p><pre><code> s e n d + m o r e --------- m o n e y </code></pre> how about considering it as a special case of integer linear programming for which there is an enormous literature of powerful techniques all of which are just applied math and can be coded up in Fortran, ..., C, etc. with no mention at all of functional programming or monads?<p>Moreover there are several highly polished software packages that implement the applied math.<p>For a detailed formulation as integer linear programming there is:<p><pre><code> Find d, e, m, n, o, r, s, y to solve maximize z = d + e + m + n + o + r + s + y subject to 1000 * s + 100 * e + 10 * n + d + 1000 * m + 100 * o + 10 * r + e - 10000 * m - 1000 * o - 100 * n - 10 * e - y &lt;= 0 d, e, m, n, o, r, s, y &lt;= 9 d, e, m, n, o, r, s, y &gt;= 0 and d, e, m, n, o, r, s, y integers. </code></pre> More generally, that constraint satisfaction is often just looking for a feasible solution to a linear or linear integer program is part of why ILOG and SAP used the R. Bixby optimization software C-PLEX.<p>Similarly if functional programming and monads can make good progress on linear and&#x2F;or linear integer programming, then there are some people in parts of the applied math, operations research, and engineering communities that would be very interested.<p>And, of course, since integer linear programming is in NP-complete, really good work would win a Clay Math prize of $1 million.<p>In more detail, at<p><a href="http:&#x2F;&#x2F;www.zweigmedia.com&#x2F;RealWorld&#x2F;simplex.html" rel="nofollow">http:&#x2F;&#x2F;www.zweigmedia.com&#x2F;RealWorld&#x2F;simplex.html</a><p>can get linear and linear integer programming on-line.<p>Then for the sample problem, in the format of that on-line solver asking for just linear programming and not integer linear programming, the problem formulation is<p><pre><code> maximize p = d + e + m + n + o + r + s + y subject to 1000 s + 100 e + 10 n + 1 d + 1000 m + 100 o + 10 r + 1 e - 10000 m - 1000 o - 100 n - 10 e - 1 y &lt;= 0, d + e + m + n + o + r + s + y &gt;= 1, d &lt;= 9, e &lt;= 9, m &lt;= 9, n &lt;= 9, o &lt;= 9, r &lt;= 9, s &lt;= 9, y &lt;= 9 </code></pre> Note: In the above, the on-line solver wants the first constraint to be all on one line.<p>Then from the on-line solver an optimal soluion is:<p>p = 18;<p>d = 9, e = 0, m = 0, n = 0, o = 0, r = 0, s = 0, y = 9<p>in which case this solution to the sample problem becomes just<p><pre><code> 9 + 9 --- 18</code></pre>
评论 #9568054 未加载
评论 #9567641 未加载