Skip to content

Add input output redux

Maarten van den Berg requested to merge add-input-output-redux into master

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 a GroupCounts (a list of integers) at initialization and provide a solve() method that returns a Cinema,
  • An online solver must accept a Cinema object at initialization and provide a try_seat_group(group_size: int) method that either returns None (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).

Edited by Maarten van den Berg

Merge request reports

Loading