From esigra at gmail.com Tue Nov 3 13:04:09 2009 From: esigra at gmail.com (Erik) Date: Tue, 03 Nov 2009 13:04:09 +0100 Subject: [Python-logic] Is this the tool to solve this little problem? Message-ID: <4AF01C39.20500@gmail.com> I was looking for a simple tool to solve little problems. For example I would like to give the following input: k * 160 + m * 30 + n * 15 = 700 k + m + n ? 6 Then I would like to get the following output: k = 4, m = 2, n = 0 Here is a textual description of the problem: An item of meat costs 160. An item of fish costs 30. An item of milk costs 15. Someone spent 700 and bought at most 6 items. What did he buy? If the second line of input would be omitted (at most 6 items), the output should include more solutions, such as: k = 4, m = 0, n = 4 I searched for a program to do this kind of calculations. I would prefer something that is as easy to use as for example the factor program of GNU coreutils. The closest thing that I stumbled upon was logilab-constraint. But I have not figured out if it is the right tool. I do not even know Python. (Just wrote 1 little script in it and modified some others when I had to.) I am not sure if this example is an assingnment problem, or if it should rather be classified as an integer programming problem or constraint satisfaction problem. From nicolas.chauvat at logilab.fr Tue Nov 3 13:25:01 2009 From: nicolas.chauvat at logilab.fr (Nicolas Chauvat) Date: Tue, 3 Nov 2009 13:25:01 +0100 Subject: [Python-logic] Is this the tool to solve this little problem? In-Reply-To: <4AF01C39.20500@gmail.com> References: <4AF01C39.20500@gmail.com> Message-ID: <20091103122501.GA17917@volans.logilab.fr> Hello, On Tue, Nov 03, 2009 at 01:04:09PM +0100, Erik wrote: > I was looking for a simple tool to solve little problems. For example I > would like to give the following input: > > k * 160 + m * 30 + n * 15 = 700 > k + m + n ? 6 > > Then I would like to get the following output: > k = 4, m = 2, n = 0 > > ... > > I am not sure if this example is an assingnment problem, or if it should > rather be classified as an integer programming problem or constraint > satisfaction problem. To solve that kind of problem, you can use either http://www.logilab.org/project/logilab-constraint/ http://code.google.com/p/pulp-or/ Look at the examples in both packages and you will find what you are looking for. http://hg.logilab.org/logilab/constraint/file/3d51e72774e6/examples http://code.google.com/p/pulp-or/wiki/OptimisationWithPuLP -- Nicolas Chauvat logilab.fr - services en informatique scientifique et gestion de connaissances