Add input output redux
Replaces !4 (closed).
This MR defines a common protocol (what an "interface" is in C#-land) for offline and online solvers and adds a command to select and invoke an offline solver on an instance of the offline problem.
The protocols for offline and online solvers are defined in types.py
and essentially mean the following:
- An offline solver must accept a
Cinema
and aGroupCounts
(a list of integers) at initialization and provide asolve()
method that returns a Cinema, - An online solver must accept a
Cinema
object at initialization and provide atry_seat_group(group_size: int)
method that either returnsNone
(if the solver cannot seat a group of this size) or return a 2-tuple of the coordinates where the solver seated the group.
This allows our solver to solve the following exciting instances of the offline problem:
$ cat dankmemes.cinema
3
3
111
101
111
1 0 0 0 0 0 0 0
$ cli offline dankmemes.cinema
111
101
11x
$ cli offline -
6
9
011101111
111101111
111101111
000000000
111101111
111101111
1 0 0 0 0 0 0 0
011101111
111101111
111101111
000000000
111101111
11110111x
More advanced offline solvers can be added to this command by defining classes that implement the same protocol and then adding them to the OfflineSolvers
enum in cli.py
.
This PR also makes several changes to types.py
and offline.py
to make it behave according to the specification (seats diagonal to a seated group were blocked incorrectly).