Book Image

Clojure Data Structures and Algorithms Cookbook

By : Rafik Naccache
Book Image

Clojure Data Structures and Algorithms Cookbook

By: Rafik Naccache

Overview of this book

Table of Contents (14 chapters)
Clojure Data Structures and Algorithms Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Resolving cost and profit optimization problems


For this recipe, we will study optimization problems. For these, you are given a set of constraints on some variables, say:

4x+3y < 30
2x+4y < 10

You are then asked to maximize or minimize a function of these variables, (if constraints are inferior, then you'll have to maximize and vice versa), for example:

max(z=13 x + 7 y)

This is called the objective function. Generally speaking, such problems are called linear programs, and the algorithm used for resolving these is called the simplex algorithm.

However, the simplex algorithm operates on real variables, that is, the variables that take real values. This is problematic if the solution to the problem can only be a compound of natural numbers. For instance, let's assume that some bakery calls you to help them optimize their profit. They tell you that they produce three kinds of products: bread, croissants, and muffins. The bread takes 2 units of sugar and 4 units of flour, the croissant takes...