Skip to content

Commit a64df6a

Browse files
committed
fixed some issues
1 parent a906dc0 commit a64df6a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

moptipy/algorithms/luby_restarts.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
from moptipy.utils.logger import CSV_SEPARATOR, KeyValueLogSection
2929

3030

31-
@numba.njit(cache=True)
32-
def _luby(i: int) -> int:
31+
@numba.njit(cache=True, inline="always", fastmath=True, boundscheck=False)
32+
def luby(i: int) -> int:
3333
"""
3434
Compute the Luby sequence.
3535
36-
>>> [_luby(ii) for ii in range(1, 65)]
36+
>>> [luby(ii) for ii in range(1, 65)]
3737
[1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8, 1, 1, 2, 1, 1, 2, 4, 1, \
3838
1, 2, 1, 1, 2, 4, 8, 16, 1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8, \
3939
1, 1, 2, 1, 1, 2, 4, 1, 1, 2, 1, 1, 2, 4, 8, 16, 32, 1]
@@ -48,7 +48,8 @@ def _luby(i: int) -> int:
4848
return two_by_k_minus_one
4949
if i >= two_by_k:
5050
continue
51-
return _luby((i - two_by_k_minus_one) + 1)
51+
i = (i - two_by_k_minus_one) + 1
52+
two_by_k = 1
5253

5354

5455
class __LubyAlgorithm(Algorithm):
@@ -98,7 +99,7 @@ def solve(self, process: Process) -> None:
9899
restarts.append((process.get_consumed_fes(),
99100
process.get_consumed_time_millis()))
100101
index = index + 1
101-
with for_fes(process, base * _luby(index)) as prc:
102+
with for_fes(process, base * luby(index)) as prc:
102103
als: Callable[[str, str], None] = prc.add_log_section
103104

104105
def __als(t: str, c: str, _a=als, _i=index) -> None:
@@ -151,7 +152,7 @@ def solve_mo(self, process: MOProcess) -> None:
151152
restarts.append((process.get_consumed_fes(),
152153
process.get_consumed_time_millis()))
153154
index = index + 1
154-
with for_fes(process, base * _luby(index)) as prc:
155+
with for_fes(process, base * luby(index)) as prc:
155156
als: Callable[[str, str], None] = prc.add_log_section
156157

157158
def __als(t: str, c: str, _a=als, _i=index) -> None:

moptipy/examples/bitstrings/labs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
`F(x) = n² / (n * E(X))`
2020
21-
This problem is different than the other bit-string based problems, because we
21+
This problem is different from the other bit-string based problems, because we
2222
only know the optimal solutions for few, smaller instances. For larger
2323
instances, we only have lower bounds of the energy.
2424

moptipy/operators/permutations/op1_swap2.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
This operator performs one swap. It is similar to :class:`~moptipy.operators.\
4747
permutations.op1_swapn.Op1SwapN`, which performs a random number of swaps.
4848
"""
49-
from typing import Callable, Final
49+
from typing import Final
5050

5151
import numba # type: ignore
5252
import numpy as np
@@ -56,8 +56,8 @@
5656

5757

5858
@numba.njit(cache=True, inline="always", fastmath=True, boundscheck=False)
59-
def swap_2(random: Generator, dest: np.ndarray, # +book
60-
x: np.ndarray) -> None: # +book
59+
def swap_2(random: Generator, dest: np.ndarray,
60+
x: np.ndarray) -> None:
6161
"""
6262
Copy `x` into `dest` and swap two different values in `dest`.
6363
@@ -87,12 +87,11 @@ def swap_2(random: Generator, dest: np.ndarray, # +book
8787
# start book
8888
dest[:] = x[:] # First, we copy `x` to `dest`.
8989
length: Final[int] = len(dest) # Get the length of `dest`.
90-
rint: Callable[[int, int], int] = random.integers # fast call
9190

92-
i1: Final[int] = rint(0, length) # first random index
91+
i1: Final[int] = random.integers(0, length) # first random index
9392
v1: Final = dest[i1] # Get the value at the first index.
9493
while True: # Repeat until we find a different value.
95-
i2: int = rint(0, length) # second random index
94+
i2: int = random.integers(0, length) # second random index
9695
v2 = dest[i2] # Get the value at the second index.
9796
if v1 != v2: # If both values different...
9897
dest[i2] = v1 # store v1 where v2 was

moptipy/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from typing import Final
33

44
#: the version string of `moptipy`
5-
__version__: Final[str] = "0.9.143"
5+
__version__: Final[str] = "0.9.144"

0 commit comments

Comments
 (0)