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
abc7aa5a
Unverified
Commit
abc7aa5a
authored
4 years ago
by
Maarten van den Berg
Browse files
Options
Downloads
Patches
Plain Diff
Delete sub_prob.py
parent
1fa81170
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cinematinator/sub_prob.py
+0
-205
0 additions, 205 deletions
cinematinator/sub_prob.py
with
0 additions
and
205 deletions
cinematinator/sub_prob.py
deleted
100644 → 0
+
0
−
205
View file @
1fa81170
"""
This is a standalone impelementation of a scan algorithm:
For every permutation of family order
try to seat them from left to right
if all seated terminate
"""
import
copy
w
=
9
h
=
6
cinema
=
[]
group_descr
=
[
4
,
4
,
0
,
1
,
1
,
0
,
0
,
0
]
# group_descr = [2,2,1,1,0,0,0,0]
groups
=
[]
for
el
in
range
(
len
(
group_descr
)):
for
i
in
range
(
group_descr
[
el
]):
groups
.
append
(
el
+
1
)
groups
.
reverse
()
print
(
groups
)
max_people
=
sum
(
groups
)
def
is_free
(
cinema
,
x
,
y
):
if
x
<
0
or
x
>=
w
:
return
False
if
y
<
0
or
y
>=
h
:
return
False
return
cinema
[
x
+
w
*
y
]
==
1
def
is_safe
(
cinema
,
x
,
y
):
if
x
<
0
or
x
>=
w
:
return
True
if
y
<
0
or
y
>=
h
:
return
True
return
cinema
[
x
+
w
*
y
]
==
1
or
cinema
[
x
+
w
*
y
]
==
0
def
can_seat
(
cinema
,
x
,
y
):
# is the seat free?
ret
=
is_free
(
cinema
,
x
,
y
)
# is the rest free?
ret
&=
is_safe
(
cinema
,
x
+
1
,
y
)
ret
&=
is_safe
(
cinema
,
x
+
1
,
y
+
1
)
ret
&=
is_safe
(
cinema
,
x
,
y
+
1
)
ret
&=
is_safe
(
cinema
,
x
-
1
,
y
+
1
)
ret
&=
is_safe
(
cinema
,
x
-
1
,
y
)
ret
&=
is_safe
(
cinema
,
x
-
1
,
y
+
1
)
ret
&=
is_safe
(
cinema
,
x
,
y
+
1
)
ret
&=
is_safe
(
cinema
,
x
+
1
,
y
+
1
)
# extra two seats on the row
ret
&=
is_safe
(
cinema
,
x
-
2
,
y
)
ret
&=
is_safe
(
cinema
,
x
+
2
,
y
)
return
ret
def
can_group_seat
(
cinema
,
x
,
y
,
s
):
ret
=
True
for
i
in
range
(
x
,
x
+
s
):
ret
&=
can_seat
(
cinema
,
i
,
y
)
return
ret
def
set_group_seat
(
cinema
,
x
,
y
,
s
):
for
i
in
range
(
x
,
x
+
s
):
cinema
[
i
+
w
*
y
]
=
2
def
print_cinema
(
cinema
):
for
y
in
range
(
h
):
for
x
in
range
(
w
):
print
(
"
x
"
if
cinema
[
x
+
w
*
y
]
==
2
else
cinema
[
x
+
w
*
y
],
end
=
""
)
print
()
def
encode
(
groups
):
buckets
=
[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
]
for
group
in
groups
:
buckets
[
group
-
1
]
+=
1
return
tuple
(
buckets
)
mem
=
{}
lookups
=
0
calcs
=
0
def
main
(
groups
,
cinema
,
first
=
False
):
global
lookups
global
calcs
if
len
(
groups
)
==
0
:
return
0
max_score
=
0
group
,
groups
=
groups
[
0
],
groups
[
1
:]
# maximize the score over x and y and the first group
for
y
in
range
(
h
):
for
x
in
range
(
w
-
group
):
if
first
:
print
(
x
,
y
)
if
not
can_group_seat
(
cinema
,
x
,
y
,
group
):
continue
# copy the cinema and seat the group
new_cinema
=
copy
.
copy
(
cinema
)
set_group_seat
(
new_cinema
,
x
,
y
,
group
)
encoded_groups
=
encode
(
groups
)
encoded_cinema
=
tuple
(
new_cinema
)
mem_key
=
(
encoded_groups
,
encoded_cinema
)
if
mem_key
in
mem
:
score
=
group
+
mem
[
mem_key
]
lookups
+=
1
else
:
rest_score
=
main
(
groups
,
new_cinema
)
score
=
group
+
rest_score
mem
[
mem_key
]
=
rest_score
calcs
+=
1
max_score
=
max
(
score
,
max_score
)
# Final case, calculate the score when the group is discarded
base_score
=
0
encoded_groups
=
encode
(
groups
)
encoded_cinema
=
tuple
(
cinema
)
mem_key
=
(
encoded_groups
,
encoded_cinema
)
if
mem_key
in
mem
:
base_score
=
mem
[
mem_key
]
else
:
base_score
=
main
(
groups
,
cinema
)
mem
[
mem_key
]
=
base_score
return
max
(
max_score
,
base_score
)
def
go
():
cinema
=
[
0
,
1
,
1
,
1
,
0
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
1
,
1
,
1
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
1
,
1
,
1
,
1
,
0
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
0
,
1
,
1
,
1
,
1
,
]
print
(
main
(
groups
,
cinema
,
True
))
print
(
f
"
lookups:
{
lookups
}
"
)
print
(
f
"
calcs:
{
calcs
}
"
)
go
()
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