Skip to content

Commit 4438c4b

Browse files
author
Wouter Coppieters
committed
Added more complex example to README.md
1 parent c057140 commit 4438c4b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,31 @@ You can then play with and attempt LP and MIP problems straight from the command
285285
=> -2.0
286286

287287
[10] pry(main)> (2 * X_i + 15 * Y_f).evaluate
288-
=> 251.0
288+
=> 251.0
289+
290+
291+
### A larger example
292+
Here is a basic example of how Rulp can help you model problems with a large number of variables.
293+
Suppose we are playing an IOS app which contains in-app purchases. Each of these in-app purchases costs
294+
a variable amount and gives us a certain number of in-game points. Suppose our mother gave us $55 to spend.
295+
We want to find the maximal number of in-game points we can buy using this money. Here is a simple example
296+
of how we could use Rulp to formulate this problem.
297+
298+
We decide to model each of these possible purchases as a binary variable (as we either purchase them or
299+
we don't. We can't partially purchase one.)
300+
301+
# Generate the data randomly for this example.
302+
costs, points = [*0..1000].map do |i|
303+
[Purchase_b(i) * Random.rand(1.0..3.0), Purchase_b(i) * Random.rand(5.0..10.0)]
304+
end.transpose.map(&:sum) #We sum the array of points and array of costs to create a Rulp expression
305+
306+
# And this is where the magic happens!. We ask rulp to maximise the number of points given
307+
# the constraint that costs must be less than $55
308+
309+
Rulp::Max(points)[
310+
costs < 55
311+
].solve
312+
=> 538.2125623353652 (# You will get a different value as data was generated randomly)
313+
314+
# Now how do we check which purchases were selected?
315+
selected_purchases = [*0..1000].select{|i| Purchase_b(i).value }

0 commit comments

Comments
 (0)