moptipyapps.spoc.spoc_4.challenge_1.beginner package

The Luna Tomato Logistics beginner problem.

Subpackages

Submodules

moptipyapps.spoc.spoc_4.challenge_1.beginner.base_obj module

A base object with stuff for handling the beginner problem.

class moptipyapps.spoc.spoc_4.challenge_1.beginner.base_obj.BaseObjectWithArrays(instance)[source]

Bases: object

The objective function of the beginner problem.

dest

the destination orbit usage

earth

the earth orbit usage

instance: Final[Instance]

the instance

lunar

the lunar orbit usage

moptipyapps.spoc.spoc_4.challenge_1.beginner.experiment module

A small example experiment.

moptipyapps.spoc.spoc_4.challenge_1.beginner.experiment.base_setup(instance, ilogger=<moptipy.api.improvement_logger.FileImprovementLoggerFactory object>)[source]

Create the basic setup.

Parameters:
  • instance (Instance) – the instance to use

  • title – a title

  • desc – a description

  • ilogger (FileImprovementLoggerFactory, default: <moptipy.api.improvement_logger.FileImprovementLoggerFactory object at 0x7f42b8520380>) – the logger to use

Return type:

tuple[Permutations, Execution]

Returns:

the search space and the basic execution

moptipyapps.spoc.spoc_4.challenge_1.beginner.experiment.rls_1(instance)[source]

Create the RLS setup.

Parameters:

instance (Instance) – the instance to use

Return type:

Execution

Returns:

the RLS

moptipyapps.spoc.spoc_4.challenge_1.beginner.experiment.rls_n(instance)[source]

Create the RLS setup.

Parameters:

instance (Instance) – the instance to use

Return type:

Execution

Returns:

the RLS

moptipyapps.spoc.spoc_4.challenge_1.beginner.experiment.run(base_dir)[source]

Run the experiment.

Parameters:

base_dir (str) – the base directory

Return type:

None

moptipyapps.spoc.spoc_4.challenge_1.beginner.instance module

The instance of the Luna Tomato Logistics beginner problem.

>>> inst1 = Instance("matching-i")
>>> inst1.n
25000
>>> inst1.shape
(25000, 4)
>>> list(map(int, inst1[0, :]))
[3390, 4454, 3664, 267]
>>> inst1[0, 1]
np.int64(4454)
>>> inst1.penalty
125526621
>>> inst1.lengths
(5000, 5000, 5000)
>>> inst1.name
'matching-i'
>>> inst1 is Instance("matching-i")
True
>>> inst2 = Instance("matching-ii")
>>> inst2.n
92103
>>> inst2.shape
(92103, 4)
>>> list(map(int, inst2[0, :]))
[5559, 5444, 3794, 9723]
>>> inst2[0, 1]
np.int64(5444)
>>> inst2.penalty
460191177
>>> inst2.lengths
(10000, 10000, 10000)
>>> inst2.name
'matching-ii'
class moptipyapps.spoc.spoc_4.challenge_1.beginner.instance.Instance(name: str)[source]

Bases: ndarray, Component

The instances of the Luna Tomato Logistics beginner problem.

lengths: tuple[int, int, int]

the number of values per column

static list_instances()[source]

Get an iterable of all instances.

Return type:

Generator[Callable[[], Any], None, None]

Returns:

the iterable

>>> for ix in Instance.list_instances():
...     print(ix().name)
matching-i
matching-ii
static list_resources()[source]

Get all the beginner problem instances.

Return type:

tuple[str, str]

Returns:

the problem instance names

>>> Instance.list_resources()
('matching-i', 'matching-ii')
>>> for ix in Instance.list_resources():
...     print(Instance(ix).name)
matching-i
matching-ii
log_parameters_to(logger)[source]

Log all parameters of this component as key-value pairs.

Parameters:

logger (KeyValueLogSection) – the logger for the parameters

Return type:

None

n: int

the number of orbit pairs

name: str

set the result name

penalty: int

set the penalty

moptipyapps.spoc.spoc_4.challenge_1.beginner.objective_no_penalty module

The objective function of the beginner problem.

>>> inst = Instance("matching-i")
>>> obj = BeginnerObjectiveNP(inst)
>>> test_x = np.ndarray(inst.n, dtype=np.bool)
>>> test_x.fill(0)
>>> obj.evaluate(test_x)
0
>>> test_x[0] = 1
>>> obj.evaluate(test_x)
-267
>>> inst[0, -1]
np.int64(267)

The clash of two orbits incurs a penalty:

>>> test_x[2234] = 1
>>> obj.evaluate(test_x)
-7903
>>> -267 - 7636
-7903
class moptipyapps.spoc.spoc_4.challenge_1.beginner.objective_no_penalty.BeginnerObjectiveNP(instance)[source]

Bases: Objective

The objective function of the beginner problem.

evaluate(x)[source]

Evaluate the objective function of the beginner problem.

Parameters:

x – the solution vector

Return type:

int

Returns:

the result

instance: Final[Instance]

the instance

log_parameters_to(logger)[source]

Log all parameters of this component as key-value pairs.

Parameters:

logger (KeyValueLogSection) – the logger for the parameters

Return type:

None

lower_bound()[source]

Get the lower bound.

Return type:

int

Returns:

the lower bound

upper_bound()[source]

Get the upper bound.

Return type:

int

Returns:

the upper bound

moptipyapps.spoc.spoc_4.challenge_1.beginner.objective_with_penalty module

The objective function of the beginner problem.

>>> inst = Instance("matching-i")
>>> obj = BeginnerObjectiveP(inst)
>>> test_x = np.ndarray(inst.n, dtype=np.bool)
>>> test_x.fill(0)
>>> obj.evaluate(test_x)
0
>>> test_x[0] = 1
>>> obj.evaluate(test_x)
-267
>>> inst[0, -1]
np.int64(267)

The clash of two orbits incurs a penalty:

>>> test_x[2234] = 1
>>> obj.evaluate(test_x)
125518718
>>> inst.penalty - 267 - 7636
125518718
class moptipyapps.spoc.spoc_4.challenge_1.beginner.objective_with_penalty.BeginnerObjectiveP(instance)[source]

Bases: BaseObjectWithArrays, Objective

The objective function of the beginner problem.

evaluate(x)[source]

Evaluate the objective function of the beginner problem.

Parameters:

x – the solution vector

Return type:

int

Returns:

the result

log_parameters_to(logger)[source]

Log all parameters of this component as key-value pairs.

Parameters:

logger (KeyValueLogSection) – the logger for the parameters

Return type:

None

lower_bound()[source]

Get the lower bound.

Return type:

int

Returns:

the lower bound

upper_bound()[source]

Get the upper bound.

Return type:

int

Returns:

the upper bound

moptipyapps.spoc.spoc_4.challenge_1.beginner.permutation_encoding module

The permutation-based encoding.

class moptipyapps.spoc.spoc_4.challenge_1.beginner.permutation_encoding.PermutationEncoding(instance)[source]

Bases: BaseObjectWithArrays, Encoding

The permutation-based decoding function of the beginner problem.

decode(x, y)[source]

Decode a permutation to a selection.

Parameters:
  • x – the permutation

  • y – the selection

Return type:

None