Coverage for moptipy / examples / bitstrings / ising1d.py: 68%
22 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-24 08:49 +0000
1"""
2The one-dimensional Ising problem.
4The one-dimensional Ising problem describes a ring. For each bit that differs
5from its (right-side) neighboring bit, a penalty of 1 is incurred. The optimum
6is a bit string of either all ones or all zeros. The optimal objective value
7is 0, the worst-possible one is `n`.
91. Simon Fischer and Ingo Wegener. The one-dimensional Ising model: Mutation
10 versus recombination. *Theoretical Computer Science.* 344(2-3):208-225.
11 November 2005. doi: https://doi.org/10.1016/j.tcs.2005.04.002
122. Carola Doerr and Furong Ye and Naama Horesh and Hao Wang and Ofer M. Shir
13 and Thomas Bäck. Benchmarking Discrete Optimization Heuristics with
14 IOHprofiler. Applied Soft Computing 88:106027, March 2020,
15 doi: https://doi.org/10.1016/j.asoc.2019.106027.
163. Clarissa Van Hoyweghen, David Edward Goldberg, and Bart Naudts. From Twomax
17 To The Ising Model: Easy And Hard Symmetrical Problems. *In Proceedings of
18 the Genetic and Evolutionary Computation Conference (GECCO'02),* July 9-13,
19 2002, New York, NY, USA, pages 626-633. Morgan Kaufmann.
20 http://gpbib.cs.ucl.ac.uk/gecco2002/GA013.pdf
214. Thomas Weise, Zhize Wu, Xinlu Li, Yan Chen, and Jörg Lässig. Frequency
22 Fitness Assignment: Optimization without Bias for Good Solutions can be
23 Efficient. *IEEE Transactions on Evolutionary Computation (TEVC)*.
24 27(4):980-992. August 2023.
25 doi: https://doi.org/10.1109/TEVC.2022.3191698
26"""
28from typing import Callable, Iterator, cast
30import numba # type: ignore
31import numpy as np
33from moptipy.examples.bitstrings.bitstring_problem import BitStringProblem
36@numba.njit(nogil=True, cache=True)
37def ising1d(x: np.ndarray) -> int:
38 """
39 Compute the objective value of the 1-dimensional Ising problem.
41 :param x: the np array
42 :return: the ising1d function value
44 >>> ising1d(np.array([True, True, True, True, True]))
45 0
46 >>> ising1d(np.array([False, False, False, False, False]))
47 0
48 >>> ising1d(np.array([False, False, False, True, False]))
49 2
50 >>> ising1d(np.array([True, False, False, False, False]))
51 2
52 >>> ising1d(np.array([False, False, False, False, True]))
53 2
54 >>> ising1d(np.array([True, False, False, False, True]))
55 2
56 >>> ising1d(np.array([True, False, True, False, False]))
57 4
58 >>> ising1d(np.array([True, False, True, False, True, False]))
59 6
61 # n = 1 and 0 true bits
62 >>> ising1d(np.array([0]))
63 0
65 # n = 1 and 1 true bit
66 >>> ising1d(np.array([1]))
67 0
69 # n = 2 and 0 true bits
70 >>> ising1d(np.array([0, 0]))
71 0
73 # n = 2 and 1 true bit
74 >>> ising1d(np.array([1, 0]))
75 2
77 # n = 2 and 1 true bit
78 >>> ising1d(np.array([0, 1]))
79 2
81 # n = 2 and 1 true bit
82 >>> ising1d(np.array([0, 1]))
83 2
85 # n = 2 and 2 true bits
86 >>> ising1d(np.array([1, 1]))
87 0
89 # n = 3 and 0 true bits
90 >>> ising1d(np.array([0, 0, 0]))
91 0
93 # n = 3 and 1 true bit
94 >>> ising1d(np.array([1, 0, 0]))
95 2
97 # n = 3 and 1 true bit
98 >>> ising1d(np.array([0, 0, 1]))
99 2
101 # n = 3 and 1 true bit
102 >>> ising1d(np.array([1, 0, 0]))
103 2
105 # n = 3 and 2 true bits
106 >>> ising1d(np.array([1, 0, 1]))
107 2
109 # n = 3 and 2 true bits
110 >>> ising1d(np.array([1, 0, 1]))
111 2
113 # n = 3 and 2 true bits
114 >>> ising1d(np.array([1, 1, 0]))
115 2
117 # n = 3 and 3 true bits
118 >>> ising1d(np.array([1, 1, 1]))
119 0
121 # n = 4 and 0 true bits
122 >>> ising1d(np.array([0, 0, 0, 0]))
123 0
125 # n = 4 and 1 true bit
126 >>> ising1d(np.array([1, 0, 0, 0]))
127 2
129 # n = 4 and 1 true bit
130 >>> ising1d(np.array([0, 0, 1, 0]))
131 2
133 # n = 4 and 1 true bit
134 >>> ising1d(np.array([1, 0, 0, 0]))
135 2
137 # n = 4 and 2 true bits
138 >>> ising1d(np.array([1, 0, 0, 1]))
139 2
141 # n = 4 and 2 true bits
142 >>> ising1d(np.array([1, 1, 0, 0]))
143 2
145 # n = 4 and 2 true bits
146 >>> ising1d(np.array([0, 1, 1, 0]))
147 2
149 # n = 4 and 3 true bits
150 >>> ising1d(np.array([0, 1, 1, 1]))
151 2
153 # n = 4 and 3 true bits
154 >>> ising1d(np.array([1, 1, 0, 1]))
155 2
157 # n = 4 and 3 true bits
158 >>> ising1d(np.array([0, 1, 1, 1]))
159 2
161 # n = 4 and 4 true bits
162 >>> ising1d(np.array([1, 1, 1, 1]))
163 0
165 # n = 5 and 0 true bits
166 >>> ising1d(np.array([0, 0, 0, 0, 0]))
167 0
169 # n = 5 and 1 true bit
170 >>> ising1d(np.array([0, 0, 0, 0, 1]))
171 2
173 # n = 5 and 1 true bit
174 >>> ising1d(np.array([0, 0, 0, 0, 1]))
175 2
177 # n = 5 and 1 true bit
178 >>> ising1d(np.array([0, 1, 0, 0, 0]))
179 2
181 # n = 5 and 2 true bits
182 >>> ising1d(np.array([0, 1, 0, 0, 1]))
183 4
185 # n = 5 and 2 true bits
186 >>> ising1d(np.array([0, 1, 0, 0, 1]))
187 4
189 # n = 5 and 2 true bits
190 >>> ising1d(np.array([0, 1, 1, 0, 0]))
191 2
193 # n = 5 and 3 true bits
194 >>> ising1d(np.array([1, 1, 0, 1, 0]))
195 4
197 # n = 5 and 3 true bits
198 >>> ising1d(np.array([1, 1, 1, 0, 0]))
199 2
201 # n = 5 and 3 true bits
202 >>> ising1d(np.array([1, 0, 1, 0, 1]))
203 4
205 # n = 5 and 4 true bits
206 >>> ising1d(np.array([1, 1, 1, 1, 0]))
207 2
209 # n = 5 and 4 true bits
210 >>> ising1d(np.array([1, 1, 0, 1, 1]))
211 2
213 # n = 5 and 4 true bits
214 >>> ising1d(np.array([1, 1, 0, 1, 1]))
215 2
217 # n = 5 and 5 true bits
218 >>> ising1d(np.array([1, 1, 1, 1, 1]))
219 0
221 # n = 6 and 0 true bits
222 >>> ising1d(np.array([0, 0, 0, 0, 0, 0]))
223 0
225 # n = 6 and 1 true bit
226 >>> ising1d(np.array([0, 0, 0, 0, 0, 1]))
227 2
229 # n = 6 and 1 true bit
230 >>> ising1d(np.array([0, 0, 0, 0, 1, 0]))
231 2
233 # n = 6 and 1 true bit
234 >>> ising1d(np.array([0, 1, 0, 0, 0, 0]))
235 2
237 # n = 6 and 2 true bits
238 >>> ising1d(np.array([1, 1, 0, 0, 0, 0]))
239 2
241 # n = 6 and 2 true bits
242 >>> ising1d(np.array([1, 1, 0, 0, 0, 0]))
243 2
245 # n = 6 and 2 true bits
246 >>> ising1d(np.array([0, 0, 0, 1, 1, 0]))
247 2
249 # n = 6 and 3 true bits
250 >>> ising1d(np.array([1, 0, 0, 1, 0, 1]))
251 4
253 # n = 6 and 3 true bits
254 >>> ising1d(np.array([1, 0, 0, 0, 1, 1]))
255 2
257 # n = 6 and 3 true bits
258 >>> ising1d(np.array([1, 1, 0, 0, 1, 0]))
259 4
261 # n = 6 and 4 true bits
262 >>> ising1d(np.array([1, 0, 1, 1, 1, 0]))
263 4
265 # n = 6 and 4 true bits
266 >>> ising1d(np.array([1, 1, 1, 1, 0, 0]))
267 2
269 # n = 6 and 4 true bits
270 >>> ising1d(np.array([1, 1, 0, 1, 0, 1]))
271 4
273 # n = 6 and 5 true bits
274 >>> ising1d(np.array([1, 1, 1, 1, 0, 1]))
275 2
277 # n = 6 and 5 true bits
278 >>> ising1d(np.array([1, 0, 1, 1, 1, 1]))
279 2
281 # n = 6 and 5 true bits
282 >>> ising1d(np.array([0, 1, 1, 1, 1, 1]))
283 2
285 # n = 6 and 6 true bits
286 >>> ising1d(np.array([1, 1, 1, 1, 1, 1]))
287 0
289 # n = 7 and 0 true bits
290 >>> ising1d(np.array([0, 0, 0, 0, 0, 0, 0]))
291 0
293 # n = 7 and 1 true bit
294 >>> ising1d(np.array([0, 0, 0, 1, 0, 0, 0]))
295 2
297 # n = 7 and 1 true bit
298 >>> ising1d(np.array([0, 0, 0, 0, 0, 1, 0]))
299 2
301 # n = 7 and 1 true bit
302 >>> ising1d(np.array([0, 0, 0, 0, 0, 1, 0]))
303 2
305 # n = 7 and 2 true bits
306 >>> ising1d(np.array([0, 1, 1, 0, 0, 0, 0]))
307 2
309 # n = 7 and 2 true bits
310 >>> ising1d(np.array([1, 0, 0, 0, 0, 1, 0]))
311 4
313 # n = 7 and 2 true bits
314 >>> ising1d(np.array([1, 0, 0, 0, 0, 0, 1]))
315 2
317 # n = 7 and 3 true bits
318 >>> ising1d(np.array([1, 0, 0, 0, 0, 1, 1]))
319 2
321 # n = 7 and 3 true bits
322 >>> ising1d(np.array([1, 0, 1, 0, 0, 1, 0]))
323 6
325 # n = 7 and 3 true bits
326 >>> ising1d(np.array([1, 0, 0, 1, 0, 1, 0]))
327 6
329 # n = 7 and 4 true bits
330 >>> ising1d(np.array([0, 1, 1, 0, 1, 1, 0]))
331 4
333 # n = 7 and 4 true bits
334 >>> ising1d(np.array([0, 1, 0, 1, 1, 0, 1]))
335 6
337 # n = 7 and 4 true bits
338 >>> ising1d(np.array([1, 1, 1, 0, 1, 0, 0]))
339 4
341 # n = 7 and 5 true bits
342 >>> ising1d(np.array([1, 0, 1, 1, 1, 0, 1]))
343 4
345 # n = 7 and 5 true bits
346 >>> ising1d(np.array([0, 1, 1, 1, 0, 1, 1]))
347 4
349 # n = 7 and 5 true bits
350 >>> ising1d(np.array([1, 1, 1, 0, 1, 1, 0]))
351 4
353 # n = 7 and 6 true bits
354 >>> ising1d(np.array([1, 1, 1, 0, 1, 1, 1]))
355 2
357 # n = 7 and 6 true bits
358 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 0]))
359 2
361 # n = 7 and 6 true bits
362 >>> ising1d(np.array([0, 1, 1, 1, 1, 1, 1]))
363 2
365 # n = 7 and 7 true bits
366 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 1]))
367 0
369 # n = 8 and 0 true bits
370 >>> ising1d(np.array([0, 0, 0, 0, 0, 0, 0, 0]))
371 0
373 # n = 8 and 1 true bit
374 >>> ising1d(np.array([0, 0, 1, 0, 0, 0, 0, 0]))
375 2
377 # n = 8 and 1 true bit
378 >>> ising1d(np.array([0, 0, 1, 0, 0, 0, 0, 0]))
379 2
381 # n = 8 and 1 true bit
382 >>> ising1d(np.array([0, 0, 0, 0, 0, 1, 0, 0]))
383 2
385 # n = 8 and 2 true bits
386 >>> ising1d(np.array([1, 0, 1, 0, 0, 0, 0, 0]))
387 4
389 # n = 8 and 2 true bits
390 >>> ising1d(np.array([0, 0, 0, 0, 1, 1, 0, 0]))
391 2
393 # n = 8 and 2 true bits
394 >>> ising1d(np.array([0, 0, 0, 1, 0, 0, 0, 1]))
395 4
397 # n = 8 and 3 true bits
398 >>> ising1d(np.array([0, 0, 1, 1, 1, 0, 0, 0]))
399 2
401 # n = 8 and 3 true bits
402 >>> ising1d(np.array([1, 0, 1, 0, 0, 0, 1, 0]))
403 6
405 # n = 8 and 3 true bits
406 >>> ising1d(np.array([0, 1, 0, 1, 0, 0, 1, 0]))
407 6
409 # n = 8 and 4 true bits
410 >>> ising1d(np.array([0, 1, 0, 1, 1, 0, 0, 1]))
411 6
413 # n = 8 and 4 true bits
414 >>> ising1d(np.array([1, 0, 1, 0, 1, 0, 1, 0]))
415 8
417 # n = 8 and 4 true bits
418 >>> ising1d(np.array([1, 0, 1, 0, 1, 0, 0, 1]))
419 6
421 # n = 8 and 5 true bits
422 >>> ising1d(np.array([1, 0, 1, 0, 0, 1, 1, 1]))
423 4
425 # n = 8 and 5 true bits
426 >>> ising1d(np.array([1, 1, 0, 1, 0, 0, 1, 1]))
427 4
429 # n = 8 and 5 true bits
430 >>> ising1d(np.array([1, 0, 0, 1, 0, 1, 1, 1]))
431 4
433 # n = 8 and 6 true bits
434 >>> ising1d(np.array([0, 1, 1, 1, 0, 1, 1, 1]))
435 4
437 # n = 8 and 6 true bits
438 >>> ising1d(np.array([0, 0, 1, 1, 1, 1, 1, 1]))
439 2
441 # n = 8 and 6 true bits
442 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 0, 0]))
443 2
445 # n = 8 and 7 true bits
446 >>> ising1d(np.array([1, 1, 1, 0, 1, 1, 1, 1]))
447 2
449 # n = 8 and 7 true bits
450 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 0, 1]))
451 2
453 # n = 8 and 7 true bits
454 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 0, 1]))
455 2
457 # n = 8 and 8 true bits
458 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 1, 1]))
459 0
461 # n = 9 and 0 true bits
462 >>> ising1d(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0]))
463 0
465 # n = 9 and 1 true bit
466 >>> ising1d(np.array([0, 0, 0, 0, 0, 0, 0, 1, 0]))
467 2
469 # n = 9 and 1 true bit
470 >>> ising1d(np.array([0, 0, 0, 0, 0, 1, 0, 0, 0]))
471 2
473 # n = 9 and 1 true bit
474 >>> ising1d(np.array([0, 1, 0, 0, 0, 0, 0, 0, 0]))
475 2
477 # n = 9 and 2 true bits
478 >>> ising1d(np.array([0, 1, 0, 1, 0, 0, 0, 0, 0]))
479 4
481 # n = 9 and 2 true bits
482 >>> ising1d(np.array([0, 1, 0, 0, 1, 0, 0, 0, 0]))
483 4
485 # n = 9 and 2 true bits
486 >>> ising1d(np.array([0, 1, 0, 1, 0, 0, 0, 0, 0]))
487 4
489 # n = 9 and 3 true bits
490 >>> ising1d(np.array([0, 0, 1, 0, 0, 1, 0, 1, 0]))
491 6
493 # n = 9 and 3 true bits
494 >>> ising1d(np.array([0, 0, 0, 1, 1, 0, 0, 1, 0]))
495 4
497 # n = 9 and 3 true bits
498 >>> ising1d(np.array([0, 0, 0, 1, 0, 0, 0, 1, 1]))
499 4
501 # n = 9 and 4 true bits
502 >>> ising1d(np.array([1, 0, 1, 1, 1, 0, 0, 0, 0]))
503 4
505 # n = 9 and 4 true bits
506 >>> ising1d(np.array([1, 1, 1, 0, 1, 0, 0, 0, 0]))
507 4
509 # n = 9 and 4 true bits
510 >>> ising1d(np.array([0, 1, 0, 0, 0, 1, 1, 0, 1]))
511 6
513 # n = 9 and 5 true bits
514 >>> ising1d(np.array([0, 0, 1, 1, 0, 0, 1, 1, 1]))
515 4
517 # n = 9 and 5 true bits
518 >>> ising1d(np.array([0, 1, 0, 1, 1, 0, 1, 0, 1]))
519 8
521 # n = 9 and 5 true bits
522 >>> ising1d(np.array([1, 0, 1, 1, 1, 0, 0, 1, 0]))
523 6
525 # n = 9 and 6 true bits
526 >>> ising1d(np.array([1, 0, 1, 1, 1, 1, 1, 0, 0]))
527 4
529 # n = 9 and 6 true bits
530 >>> ising1d(np.array([0, 0, 1, 1, 1, 1, 1, 1, 0]))
531 2
533 # n = 9 and 6 true bits
534 >>> ising1d(np.array([1, 1, 1, 1, 0, 1, 0, 0, 1]))
535 4
537 # n = 9 and 7 true bits
538 >>> ising1d(np.array([1, 1, 0, 1, 1, 0, 1, 1, 1]))
539 4
541 # n = 9 and 7 true bits
542 >>> ising1d(np.array([1, 1, 0, 1, 1, 1, 1, 1, 0]))
543 4
545 # n = 9 and 7 true bits
546 >>> ising1d(np.array([1, 0, 1, 0, 1, 1, 1, 1, 1]))
547 4
549 # n = 9 and 8 true bits
550 >>> ising1d(np.array([1, 0, 1, 1, 1, 1, 1, 1, 1]))
551 2
553 # n = 9 and 8 true bits
554 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 0, 1, 1]))
555 2
557 # n = 9 and 8 true bits
558 >>> ising1d(np.array([1, 1, 1, 1, 1, 0, 1, 1, 1]))
559 2
561 # n = 9 and 9 true bits
562 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1]))
563 0
565 # n = 10 and 0 true bits
566 >>> ising1d(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
567 0
569 # n = 10 and 1 true bit
570 >>> ising1d(np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 1]))
571 2
573 # n = 10 and 1 true bit
574 >>> ising1d(np.array([0, 0, 0, 1, 0, 0, 0, 0, 0, 0]))
575 2
577 # n = 10 and 1 true bit
578 >>> ising1d(np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 0]))
579 2
581 # n = 10 and 2 true bits
582 >>> ising1d(np.array([0, 1, 0, 0, 0, 0, 0, 0, 1, 0]))
583 4
585 # n = 10 and 2 true bits
586 >>> ising1d(np.array([1, 0, 0, 0, 0, 0, 0, 0, 0, 1]))
587 2
589 # n = 10 and 2 true bits
590 >>> ising1d(np.array([0, 0, 0, 0, 1, 0, 0, 0, 0, 1]))
591 4
593 # n = 10 and 3 true bits
594 >>> ising1d(np.array([1, 1, 1, 0, 0, 0, 0, 0, 0, 0]))
595 2
597 # n = 10 and 3 true bits
598 >>> ising1d(np.array([0, 0, 1, 0, 0, 0, 1, 0, 1, 0]))
599 6
601 # n = 10 and 3 true bits
602 >>> ising1d(np.array([0, 1, 0, 0, 0, 0, 1, 0, 0, 1]))
603 6
605 # n = 10 and 4 true bits
606 >>> ising1d(np.array([1, 0, 0, 1, 1, 0, 0, 0, 1, 0]))
607 6
609 # n = 10 and 4 true bits
610 >>> ising1d(np.array([0, 0, 0, 1, 1, 0, 1, 0, 0, 1]))
611 6
613 # n = 10 and 4 true bits
614 >>> ising1d(np.array([1, 1, 0, 0, 0, 0, 0, 1, 0, 1]))
615 4
617 # n = 10 and 5 true bits
618 >>> ising1d(np.array([1, 0, 0, 0, 1, 1, 1, 0, 1, 0]))
619 6
621 # n = 10 and 5 true bits
622 >>> ising1d(np.array([1, 1, 0, 0, 1, 0, 1, 0, 1, 0]))
623 8
625 # n = 10 and 5 true bits
626 >>> ising1d(np.array([0, 0, 1, 0, 0, 1, 0, 1, 1, 1]))
627 6
629 # n = 10 and 6 true bits
630 >>> ising1d(np.array([1, 1, 1, 0, 0, 1, 1, 0, 0, 1]))
631 4
633 # n = 10 and 6 true bits
634 >>> ising1d(np.array([1, 1, 0, 1, 0, 0, 1, 1, 1, 0]))
635 6
637 # n = 10 and 6 true bits
638 >>> ising1d(np.array([1, 0, 0, 0, 1, 1, 1, 0, 1, 1]))
639 4
641 # n = 10 and 7 true bits
642 >>> ising1d(np.array([1, 0, 0, 0, 1, 1, 1, 1, 1, 1]))
643 2
645 # n = 10 and 7 true bits
646 >>> ising1d(np.array([1, 0, 0, 1, 1, 1, 1, 1, 1, 0]))
647 4
649 # n = 10 and 7 true bits
650 >>> ising1d(np.array([0, 1, 1, 1, 0, 1, 0, 1, 1, 1]))
651 6
653 # n = 10 and 8 true bits
654 >>> ising1d(np.array([1, 0, 1, 1, 0, 1, 1, 1, 1, 1]))
655 4
657 # n = 10 and 8 true bits
658 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 1, 0, 1, 0]))
659 4
661 # n = 10 and 8 true bits
662 >>> ising1d(np.array([0, 1, 1, 1, 1, 1, 1, 0, 1, 1]))
663 4
665 # n = 10 and 9 true bits
666 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 1, 1, 0, 1]))
667 2
669 # n = 10 and 9 true bits
670 >>> ising1d(np.array([1, 1, 1, 1, 1, 0, 1, 1, 1, 1]))
671 2
673 # n = 10 and 9 true bits
674 >>> ising1d(np.array([1, 0, 1, 1, 1, 1, 1, 1, 1, 1]))
675 2
677 # n = 10 and 10 true bits
678 >>> ising1d(np.array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1]))
679 0
680 """
681 n: int = 0
682 prev: bool = x[-1]
683 for cur in x:
684 if cur != prev:
685 n += 1
686 prev = cur
687 return n
690class Ising1d(BitStringProblem):
691 """The one-dimensional Ising problem."""
693 def __init__(self, n: int) -> None:
694 """
695 Initialize the one-dimensional Ising problem.
697 :param n: the dimension of the problem
699 >>> Ising1d(7).n
700 7
701 >>> Ising1d(3).evaluate(np.array([True, False, True]))
702 2
703 """
704 super().__init__(n)
705 self.evaluate = ising1d # type: ignore
707 def __str__(self) -> str:
708 """
709 Get the name of the one-dimensional Ising problem.
711 :return: `ising1d_` + length of string
713 >>> Ising1d(5)
714 ising1d_5
715 """
716 return f"ising1d_{self.n}"
718 @classmethod
719 def default_instances(
720 cls: type, scale_min: int = 2, scale_max: int = 100) \
721 -> Iterator[Callable[[], "Ising1d"]]:
722 """
723 Get the 56 default instances of the :class:`Ising1d` problem.
725 :param scale_min: the minimum permitted scale, by default `2`
726 :param scale_max: the maximum permitted scale, by default `100`
727 :returns: a sequence of default :class:`Ising1d` instances
729 >>> len(list(Ising1d.default_instances()))
730 56
732 >>> [x() for x in Ising1d.default_instances()]
733 [ising1d_2, ising1d_3, ising1d_4, ising1d_5, ising1d_6, ising1d_7, \
734ising1d_8, ising1d_9, ising1d_10, ising1d_11, ising1d_12, ising1d_13, \
735ising1d_14, ising1d_15, ising1d_16, ising1d_17, ising1d_18, ising1d_19, \
736ising1d_20, ising1d_21, ising1d_22, ising1d_23, ising1d_24, ising1d_25, \
737ising1d_26, ising1d_27, ising1d_28, ising1d_29, ising1d_30, ising1d_31, \
738ising1d_32, ising1d_33, ising1d_36, ising1d_40, ising1d_41, ising1d_42, \
739ising1d_44, ising1d_48, ising1d_49, ising1d_50, ising1d_55, ising1d_59, \
740ising1d_60, ising1d_64, ising1d_66, ising1d_70, ising1d_77, ising1d_79, \
741ising1d_80, ising1d_81, ising1d_85, ising1d_88, ising1d_90, ising1d_96, \
742ising1d_99, ising1d_100]
743 """
744 return cast("Iterator[Callable[[], Ising1d]]",
745 super().default_instances( # type: ignore
746 scale_min, scale_max))