Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple benchmark #13

Merged
merged 2 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ jobs:
# example
- name: Run example/example.py
run: python example/example.py

# benchmark
- name: Run example/benchmark.py
run: python example/benchmark.py
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ print("problem:", problem)

# Get a solver
solver = rps.Solver()
print("solving...")

# Find a solution
solution = solver.solve(problem)
Expand All @@ -40,7 +39,6 @@ print("solution:", solution)
Output:
```plaintext
problem: Problem({'n': 4, 'rectangles': [{'id': 0, 'width': 4, 'height': 6, 'rotatable': False}, {'id': 1, 'width': 4, 'height': 4, 'rotatable': False}, {'id': 2, 'width': 2.1, 'height': 3.2, 'rotatable': False}, {'id': 3, 'width': 1, 'height': 5, 'rotatable': True}]})
solving...
solution: Solution({'sequence_pair': SequencePair(([0, 1, 3, 2], [3, 0, 2, 1])), 'floorplan': Floorplan({'positions': [{'id': 0, 'x': 0, 'y': 1}, {'id': 1, 'x': 4, 'y': 3.2}, {'id': 2, 'x': 5.0, 'y': 0.0}, {'id': 3, 'x': 0, 'y': 0}], 'bounding_box': (8, 7.2), 'area': 57.6})})
```

Expand Down
54 changes: 54 additions & 0 deletions example/benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2021 Kotaro Terada
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import random
import time

import rectangle_packing_solver as rps


def generate_rectangles(n=10, range_width=(1, 100), range_height=(1, 100)):
rectangles = []
for i in range(n):
rectangles.append((random.randint(range_width[0], range_width[1]), random.randint(range_height[0], range_height[1])))
return rectangles


def main():
random.seed(12345)

n_rectangles = list(range(4, 10)) + list(range(10, 50, 10))
for n in n_rectangles:
print("\n================")
print("N =", n)

rectangles = generate_rectangles(n=n)
problem = rps.Problem(rectangles=rectangles)
print("problem:", problem)

solver = rps.Solver()

start = time.time()
solution = solver.solve(problem, simanneal_minutes=0.1, simanneal_steps=100)
elapsed_time = time.time() - start
print("solution:", solution)
print(solution.floorplan.bounding_box, solution.floorplan.area)
print("elapsed_time:", elapsed_time)


if __name__ == "__main__":
main()
1 change: 0 additions & 1 deletion example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def main():

# Get a solver
solver = rps.Solver()
print("solving...")

# Find a solution
solution = solver.solve(problem)
Expand Down