@File : sphere.py @Time : 2026/05/20 15:31:48 @Author : Alejandro Marrero (amarrerd@ull.edu.es) @Version : 1.0 @Contact : amarrerd@ull.edu.es @License : (C)Copyright 2026, Alejandro Marrero @Desc : None
Sphere
Bases: Problem
Minimises the shifted sphere: f(x) = Σ (xᵢ − centerᵢ)²
Fitness is returned as −f(x) so that higher is better, matching the maximisation convention used throughout digneapy.
Source code in digneapy/domains/sphere.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
__call__(individual)
Alias for evaluate — makes SphereProblem directly callable.
Source code in digneapy/domains/sphere.py
62 63 64 | |
create_solution()
Creates a random feasible solution.
Source code in digneapy/domains/sphere.py
50 51 52 53 54 55 56 57 58 59 60 | |
evaluate(individual)
Returns (−sphere_value,) so higher fitness = closer to centre.
Source code in digneapy/domains/sphere.py
42 43 44 45 46 47 48 | |
to_file(filename)
Persists the problem centre to a plain text file.
Source code in digneapy/domains/sphere.py
70 71 72 | |
to_instance()
Converts this problem back to an Instance (center as variables).
Source code in digneapy/domains/sphere.py
66 67 68 | |
SphereDomain
Bases: Domain
Domain of 2-D shifted sphere problems.
Each instance is a 2-D point (x₀, x₁) that serves as the centre of a sphere. The two coordinates are also the features used as descriptors, so they map directly onto a 2-D GridArchive.
| Parameters: |
|
|---|
Source code in digneapy/domains/sphere.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
extract_features(instances)
Returns the raw instance coordinates as features.
Shape: (n_instances, dimension). For a 2-D domain these directly populate a 2-D GridArchive.
Source code in digneapy/domains/sphere.py
131 132 133 134 135 136 137 138 139 140 141 142 | |
extract_features_as_dict(instances)
Returns a list of {feat_name: value} dicts, one per instance.
Source code in digneapy/domains/sphere.py
144 145 146 147 148 149 150 151 | |
generate_instances(n=np.uint32(1))
Generates n random sphere centre points as Instance objects.
Source code in digneapy/domains/sphere.py
115 116 117 118 119 120 121 122 123 | |
generate_problems_from_instances(instances)
Creates one SphereProblem per instance (using variables as centre).
Source code in digneapy/domains/sphere.py
125 126 127 128 129 | |