Skip to content

Commit

Permalink
Move grant constraint definition back into let
Browse files Browse the repository at this point in the history
  • Loading branch information
lvh committed Mar 6, 2014
1 parent d24693f commit fd27884
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/hood/constraint.clj
Expand Up @@ -9,17 +9,11 @@
[apps] [apps]
(for [a apps] [:allocation a])) (for [a apps] [:allocation a]))


(defn grant-constraint
"An application will get between zero and the requested amount of
dollars."
[app]
($in [:allocation app] 0 (:requested app)))

(defn ^:private solve (defn ^:private solve
"Throw the constraint problem into loco." "Throw the constraint problem into loco."
[apps budget target] [apps budget target]
(let [allocs (alloc-vars apps) (let [allocs (alloc-vars apps)
grant-constraints (map grant-constraint apps) grant-constraints (map #($in [:allocation %] 0 (:requested %)) apps)
within-budget ($<= (apply $+ allocs) budget) within-budget ($<= (apply $+ allocs) budget)
constraints (conj grant-constraints within-budget)] constraints (conj grant-constraints within-budget)]
(solution constraints :maximize target))) (solution constraints :maximize target)))
Expand Down

0 comments on commit fd27884

Please sign in to comment.