Skip to content

Instantly share code, notes, and snippets.

@luismbo

luismbo/mpl.lisp Secret

Created May 22, 2020 17:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luismbo/314ded3273666ea38cbc12958bab6418 to your computer and use it in GitHub Desktop.
Save luismbo/314ded3273666ea38cbc12958bab6418 to your computer and use it in GitHub Desktop.
MPL
(define-model wedding ()
(possible-tables
guests
table-guests
happiness
max-tables)
;; variables
(dvar 'x :binary
(for i :in (param 'possible-tables)))
;; objective
(minimize (sum (* (param 'happiness i) (var 'x i))
(for i :in (param 'possible-tables))))
;; constraints
(s.t. 'maximum-number-of-tables
(<= (sum (var 'x i)
(for i :in (param 'possible-tables)))
(param 'max-tables)))
(s.t. 'seat-each-guest-once
(= (sum (var 'x i)
(for i :in (param 'possible-tables))
(where (member g (param 'table-guests i))))
1)
(for g :in (param 'guests))))
; => WEDDING
(make-instance 'wedding
:possible-tables '(a b c d e)
:guests '(alice bob carl)
:table-guests '(a (alice bob) b (alice carl) c (bob carl) d (bob) e (carl))
:happiness '(a 10 b 20 c 30 d 1 e 2)
:max-tables 2)
; => #<WEDDING [MIN] 1 variable, 2 constraints @ #x1163ccea2>
(solve *)
; ...
; => #<MPL::SOLUTION 12.0 (optimal) @ #x112bb11d2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment