Skip to content

Commit

Permalink
move to pycommons csv
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasWeise committed Apr 27, 2024
1 parent 867b4bf commit a6708d7
Show file tree
Hide file tree
Showing 12 changed files with 912 additions and 1,025 deletions.
15 changes: 2 additions & 13 deletions examples/binpacking2d_rls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
this with the example file `binpacking2d_plot.py`, where three bins are needed
by the same encoding (or four by `ImprovedBottomLeftEncoding1`).
"""
import os
from time import sleep
from webbrowser import open_new_tab

import psutil
from moptipy.algorithms.so.rls import RLS
from moptipy.api.execution import Execution
from moptipy.operators.signed_permutations.op0_shuffle_and_flip import (
Expand All @@ -27,6 +25,7 @@
)
from moptipy.spaces.signed_permutations import SignedPermutations
from moptipy.utils.plot_utils import save_figure
from moptipy.utils.sys_info import is_make_build
from pycommons.io.temp import temp_dir

from moptipyapps.binpacking2d.encodings.ibl_encoding_2 import (
Expand All @@ -39,16 +38,6 @@
from moptipyapps.binpacking2d.packing_space import PackingSpace
from moptipyapps.binpacking2d.plot_packing import plot_packing

# We do not show the generated graphics in the browser if this script is
# called from a "make" build. This small lambda checks whether there is any
# process with "make" in its name anywhere in the parent hierarchy of the
# current process.
ns = lambda prc: False if prc is None else ( # noqa: E731
"make" in prc.name() or ns(prc.parent()))

# should we show the plots?
SHOW_PLOTS_IN_BROWSER = not ns(psutil.Process(os.getppid()))

# load the problem instance
instance = Instance.from_resource("a10") # pick instance a10

Expand Down Expand Up @@ -94,7 +83,7 @@

# OK, we have now generated and saved the plot in a file.
# We will open it in the web browser if we are not in a make build.
if SHOW_PLOTS_IN_BROWSER:
if not is_make_build():
for file in files: # for each file we generated
open_new_tab(f"file://{file}") # open a browser tab
sleep(10) # sleep 10 seconds (enough time for the browser to load)
Expand Down
13 changes: 3 additions & 10 deletions examples/binpacking2d_timing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Compare the runtime of encodings on several problem instances."""
import os
from statistics import mean, median
from timeit import timeit
from typing import Any, Callable, cast

import numpy as np
import psutil
from moptipy.utils.nputils import rand_generator
from moptipy.utils.sys_info import is_make_build
from pycommons.types import type_name

from moptipyapps.binpacking2d.encodings.ibl_encoding_1 import (
Expand All @@ -18,21 +17,15 @@
from moptipyapps.binpacking2d.instance import Instance
from moptipyapps.binpacking2d.packing_space import PackingSpace

# Check if process is a sub-process of make?
ns = lambda prc: False if prc is None else ( # noqa: E731
"make" in prc.name() or ns(prc.parent()))
# Is this a make build?
IS_MAKE_BUILD = ns(psutil.Process(os.getppid()))

# Create the random number generator.
random = rand_generator(1)

# If it is a make build, use only 1 repetition, otherwise 20.
REPETITIONS = 1 if IS_MAKE_BUILD else 20
REPETITIONS = 1 if is_make_build() else 20

# The instances to iterate over: All if not make build, 20 otherwise.
INSTANCES = random.choice(Instance.list_resources(), 20, False) \
if IS_MAKE_BUILD else Instance.list_resources()
if is_make_build() else Instance.list_resources()


# We test two versions of the Improved Bottom Left Encoding
Expand Down
Loading

0 comments on commit a6708d7

Please sign in to comment.