Anneal
Simulated annealing to place snailz.
anneal(size, specimens)
Calculate specimen positions using simulated annealing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
grid size |
required |
specimens
|
Sequence[MinimalSpecimen]
|
partially-initialized specimens to place |
required |
Source code in src/snailz/anneal.py
22 23 24 25 26 27 28 29 30 31 32 33 |
|
_initial_placement(size, specimens)
Randomly initialize specimen placement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
grid size |
required |
specimens
|
Sequence[MinimalSpecimen]
|
partially-initialized specimens to place |
required |
Source code in src/snailz/anneal.py
36 37 38 39 40 41 42 43 44 45 46 |
|
_make_grid(size, specimens)
Make initial grid to track specimen positions during placement.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
grid size |
required |
specimens
|
Sequence[MinimalSpecimen]
|
partially-initialized specimens to place |
required |
Source code in src/snailz/anneal.py
49 50 51 52 53 54 55 56 57 58 59 |
|
_make_wall(size)
Make a wall of unit-mass specimens to keep actual specimens in the grid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
grid size |
required |
Source code in src/snailz/anneal.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
_move(grid, wall, specimens)
Move a randomly-selected specimen one step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grid
|
Grid[str]
|
temporary grid showing specimen positions |
required |
wall
|
Sequence[MinimalSpecimen]
|
barrier around outside of grid |
required |
specimens
|
Sequence[MinimalSpecimen]
|
specimens being moved |
required |
Source code in src/snailz/anneal.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
_point_point_force(specimens, i)
Calculate force on specimen 'i' from other specimens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
specimens
|
Sequence[MinimalSpecimen]
|
all specimens |
required |
i
|
int
|
which specimen is being moved |
required |
Returns:
Type | Description |
---|---|
tuple[float, float]
|
XY components of force. |
Source code in src/snailz/anneal.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
_wall_point_force(wall, specimen)
Calculate force on selected specimen from fixed wall.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
wall
|
Sequence[MinimalSpecimen]
|
fixed wall containing specimens |
required |
specimen
|
MinimalSpecimen
|
specimen being moved |
required |
Returns:
Type | Description |
---|---|
tuple[float, float]
|
XY components of force. |
Source code in src/snailz/anneal.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
_single_force(s0, s1)
Calculate force on specimen from another specimen.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s0
|
MinimalSpecimen
|
specimen being moved |
required |
s1
|
MinimalSpecimen
|
specimen acting on it |
required |
Returns:
Type | Description |
---|---|
tuple[float, float]
|
XY components of force. |
Source code in src/snailz/anneal.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
_clip(size, coord, force)
Calculate new coordinate (old-1, old+1, or 0 depending on force).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size
|
int
|
grid size |
required |
coord
|
int
|
X or Y coordinate |
required |
force
|
float
|
force in that direction |
required |
Returns:
Type | Description |
---|---|
int
|
New coordinate. |
Source code in src/snailz/anneal.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|