Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Python prototype
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cinematinator
Python prototype
Commits
3b76e219
Verified
Commit
3b76e219
authored
4 years ago
by
Maarten van den Berg
Browse files
Options
Downloads
Patches
Plain Diff
online.py: Add more comments
parent
abc7aa5a
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cinematinator/__init__.py
+3
-0
3 additions, 0 deletions
cinematinator/__init__.py
cinematinator/online.py
+38
-0
38 additions, 0 deletions
cinematinator/online.py
with
41 additions
and
0 deletions
cinematinator/__init__.py
+
3
−
0
View file @
3b76e219
"""
Empty file required for Python
'
s package structure.
"""
This diff is collapsed.
Click to expand it.
cinematinator/online.py
+
38
−
0
View file @
3b76e219
...
...
@@ -23,6 +23,13 @@ class OnlineFirstFitSolver:
self
.
cinema
=
cinema
def
try_seat_group
(
self
,
group_size
:
GroupSize
)
->
Optional
[
Coordinates
]:
"""
Try to seat a group using the
"
first-fit
"
strategy.
Iterate over each row from left to right, top to bottom, and seat a group in the
first found position that will fit.
"""
for
y
in
range
(
self
.
cinema
.
height
):
for
x
in
range
(
self
.
cinema
.
width
):
if
self
.
cinema
.
can_seat_group
(
x
,
y
,
group_size
):
...
...
@@ -37,6 +44,14 @@ class OnlineLastFitSolver:
self
.
cinema
=
cinema
def
try_seat_group
(
self
,
group_size
:
GroupSize
)
->
Optional
[
Coordinates
]:
"""
Try to seat a group using the
"
last-fit
"
strategy.
Iterate over each row from right to left, bottom to top, and seat a group in the
first found position that will fit.
Identical to first-fit except for `reversed` usages.
"""
for
y
in
reversed
(
range
(
self
.
cinema
.
height
)):
for
x
in
reversed
(
range
(
self
.
cinema
.
width
)):
if
self
.
cinema
.
can_seat_group
(
x
,
y
,
group_size
):
...
...
@@ -47,11 +62,25 @@ class OnlineLastFitSolver:
class
OnlineHeuristicSolver
:
"""
Allows choosing positions based on a heuristic function, which is calculated for
each spot that could fit a group of the given size.
If two locations return the same minimum value for a group size the top-leftmost
position is chosen.
"""
def
__init__
(
self
,
cinema
:
Cinema
,
heuristic
:
Heuristic
)
->
None
:
self
.
cinema
=
cinema
self
.
heuristic
=
heuristic
def
try_seat_group
(
self
,
group_size
:
GroupSize
)
->
Optional
[
Coordinates
]:
"""
Calculate the penalty value for each of the positions that will fit a group of
the given size, then choose the
"
best
"
location (with minimum penalty).
If no such position exists None is returned.
"""
potential_locations
:
List
[
Tuple
[
int
,
Coordinates
]]
=
[]
for
y
in
range
(
self
.
cinema
.
height
):
...
...
@@ -93,11 +122,20 @@ class OnlineHeuristicSolver:
def
greedy_heuristic
(
cinema
:
Cinema
,
spot
:
Coordinates
,
group_size
:
GroupSize
)
->
int
:
"""
"
Greedy
"
heuristic: returns the amount of seats that would be newly blocked by
placing a group of this size at this spot in this cinema.
"""
x
,
y
=
spot
return
cinema
.
newly_blocked_seats
(
x
,
y
,
group_size
)
def
center_heuristic
(
cinema
:
Cinema
,
spot
:
Coordinates
,
group_size
:
GroupSize
)
->
int
:
"""
"
Center
"
heuristic: prefers seating groups near to the center of the cinema (as
"
these seats have a better view
"
).
Not intended to be competitive or described in the paper.
"""
x
,
y
=
spot
left_edge
=
x
right_edge
=
x
+
group_size
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment