Skip to content

Commit 42dc111

Browse files
committed
simulated annealix simplify
1 parent 45b308d commit 42dc111

7 files changed

Lines changed: 232 additions & 124 deletions

File tree

demo/app.js

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@ const fileInfo = document.getElementById('file-info');
4343
const resetButton = document.getElementById('reset-data');
4444
const editModeCheckbox = document.getElementById('edit-mode');
4545
const resetEditsButton = document.getElementById('reset-edits');
46-
const compactnessWeightInput = document.getElementById('compactness-weight');
47-
const compactnessWeightValue = document.getElementById('compactness-weight-value');
4846
const adjacencyWeightInput = document.getElementById('adjacency-weight');
4947
const adjacencyWeightValue = document.getElementById('adjacency-weight-value');
5048
const adjacencyDiagonalInput = document.getElementById('adjacency-diagonal');
5149
const pairwiseEnabledInput = document.getElementById('pairwise-enabled');
5250
const pairwiseEdgeLimitInput = document.getElementById('pairwise-edge-limit');
5351
const pairwiseNearestCellsInput = document.getElementById('pairwise-nearest-cells');
5452
const pairwiseWeightInput = document.getElementById('pairwise-weight');
53+
const pairwiseControlsWrap = document.getElementById('pairwise-controls-wrap');
54+
const pairwiseNote = document.getElementById('pairwise-note');
5555
const runPostProcessInput = document.getElementById('run-post-process');
5656
const runSAInput = document.getElementById('run-sa');
5757
const saIterInput = document.getElementById('sa-iter');
58+
const runAdjFixInput = document.getElementById('run-adj-fix');
59+
const adjFixIterInput = document.getElementById('adj-fix-iter');
60+
61+
const PAIRWISE_MIN_FEATURES = 25;
5862

5963
// Edit mode state
6064
let editModeEnabled = false;
@@ -167,14 +171,52 @@ function parseIntOr(value, fallbackValue) {
167171
}
168172

169173
function updateAdvancedValueDisplays() {
170-
if (compactnessWeightInput && compactnessWeightValue) {
171-
compactnessWeightValue.textContent = parseFloatOr(compactnessWeightInput.value, 1).toFixed(1);
172-
}
173174
if (adjacencyWeightInput && adjacencyWeightValue) {
174175
adjacencyWeightValue.textContent = parseFloatOr(adjacencyWeightInput.value, 0).toFixed(2);
175176
}
176177
}
177178

179+
function setControlEnabled(input, enabled) {
180+
if (!input) return;
181+
input.disabled = !enabled;
182+
const group = input.closest('.control-group');
183+
if (group) {
184+
group.classList.toggle('is-disabled', !enabled);
185+
}
186+
}
187+
188+
function updatePairwiseAvailability(featureCount = londonData?.length || 0) {
189+
const enabledByData = featureCount >= PAIRWISE_MIN_FEATURES;
190+
if (!pairwiseControlsWrap || !pairwiseNote) return enabledByData;
191+
192+
if (!enabledByData && pairwiseEnabledInput) {
193+
pairwiseEnabledInput.checked = false;
194+
}
195+
196+
pairwiseControlsWrap.classList.toggle('pairwise-hidden', !enabledByData);
197+
pairwiseNote.classList.toggle('pairwise-note-visible', !enabledByData);
198+
pairwiseNote.textContent = enabledByData
199+
? ''
200+
: `Pairwise adjacency is hidden for datasets with fewer than ${PAIRWISE_MIN_FEATURES} features.`;
201+
202+
return enabledByData;
203+
}
204+
205+
function updateAdvancedControlState() {
206+
const adjacencyWeight = parseFloatOr(adjacencyWeightInput?.value, 0);
207+
const pairwiseAvailable = updatePairwiseAvailability();
208+
const pairwiseEnabled = pairwiseAvailable && Boolean(pairwiseEnabledInput?.checked);
209+
const runSA = Boolean(runSAInput?.checked);
210+
const runAdjFix = Boolean(runAdjFixInput?.checked);
211+
212+
setControlEnabled(adjacencyDiagonalInput, adjacencyWeight > 0);
213+
setControlEnabled(pairwiseEdgeLimitInput, pairwiseEnabled);
214+
setControlEnabled(pairwiseNearestCellsInput, pairwiseEnabled);
215+
setControlEnabled(pairwiseWeightInput, pairwiseEnabled);
216+
setControlEnabled(saIterInput, runSA);
217+
setControlEnabled(adjFixIterInput, runAdjFix);
218+
}
219+
178220
function getFeatureKey(feature, index) {
179221
if (feature?.id !== undefined && feature?.id !== null) {
180222
return String(feature.id);
@@ -401,6 +443,7 @@ async function loadData(geojson, fileName = 'london.geojson') {
401443
currentGeoJson = fixedGeoJson;
402444
currentSourceFileName = fileName;
403445
cachedAdjacencyGraph = null;
446+
updatePairwiseAvailability(processedData.length);
404447

405448
updateRunStats({
406449
featureCount: processedData.length,
@@ -484,7 +527,6 @@ function setupEventListeners() {
484527
gridTypeSelect,
485528
distanceMetricSelect,
486529
rotatePCAInput,
487-
compactnessWeightInput,
488530
adjacencyWeightInput,
489531
adjacencyDiagonalInput,
490532
pairwiseEnabledInput,
@@ -493,7 +535,9 @@ function setupEventListeners() {
493535
pairwiseWeightInput,
494536
runPostProcessInput,
495537
runSAInput,
496-
saIterInput
538+
saIterInput,
539+
runAdjFixInput,
540+
adjFixIterInput
497541
];
498542

499543
let allocationTimeout = null;
@@ -553,16 +597,25 @@ function setupEventListeners() {
553597
if (input === compactnessSlider) {
554598
compactnessValue.textContent = compactnessSlider.value;
555599
}
556-
if (input === compactnessWeightInput || input === adjacencyWeightInput) {
600+
if (input === adjacencyWeightInput) {
557601
updateAdvancedValueDisplays();
558602
}
559-
if (input === compactnessSlider || input === compactnessWeightInput || input === adjacencyWeightInput) {
603+
if (
604+
input === adjacencyWeightInput ||
605+
input === pairwiseEnabledInput ||
606+
input === runSAInput ||
607+
input === runAdjFixInput
608+
) {
609+
updateAdvancedControlState();
610+
}
611+
if (input === compactnessSlider || input === adjacencyWeightInput) {
560612
scheduleAllocation(120);
561613
}
562614
});
563615
});
564616

565617
updateAdvancedValueDisplays();
618+
updateAdvancedControlState();
566619

567620
// File upload handler
568621
fileUpload.addEventListener('change', async (event) => {
@@ -666,16 +719,17 @@ async function allocateAndDraw() {
666719
gridType: gridTypeSelect.value,
667720
distanceMetric: distanceMetricSelect.value,
668721
rotateByPCA: rotatePCAInput.checked,
669-
compactnessWeight: parseFloatOr(compactnessWeightInput?.value, 1),
670722
adjacencyWeight: parseFloatOr(adjacencyWeightInput?.value, 0),
671723
adjacencyDiagonal: Boolean(adjacencyDiagonalInput?.checked),
672724
runPostProcess: Boolean(runPostProcessInput?.checked),
673725
runSA: Boolean(runSAInput?.checked),
674726
saIter: parseIntOr(saIterInput?.value, 2000),
727+
runAdjacencyFix: Boolean(runAdjFixInput?.checked),
728+
adjFixIter: parseIntOr(adjFixIterInput?.value, 500),
675729
mip: () => new GLPKSolver(glpkInstance)
676730
};
677731

678-
const pairwiseEnabled = Boolean(pairwiseEnabledInput?.checked);
732+
const pairwiseEnabled = updatePairwiseAvailability() && Boolean(pairwiseEnabledInput?.checked);
679733
if (pairwiseEnabled) {
680734
if (!cachedAdjacencyGraph && currentGeoJson?.features) {
681735
cachedAdjacencyGraph = computeAdjacencyGraph(currentGeoJson.features);

demo/embedding-london.json

Lines changed: 66 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -973,136 +973,136 @@
973973
],
974974
"embedding": {
975975
"Kingston upon Thames": {
976-
"x": 0.658939630950618,
977-
"y": 0.44518711726922877
976+
"x": 0.3781378193139724,
977+
"y": 0.7158824167363638
978978
},
979979
"Croydon": {
980-
"x": 0.5032075521794896,
981-
"y": 0.4909822221590237
980+
"x": 0.35457038042187317,
981+
"y": 0.5664858025104786
982982
},
983983
"Bromley": {
984-
"x": 0.3941008137634968,
985-
"y": 0.4980568512854997
984+
"x": 0.36502221422892867,
985+
"y": 0.46205535597745984
986986
},
987987
"Hounslow": {
988-
"x": 0.6424077775434568,
989-
"y": 0.3414248554084034
988+
"x": 0.46704770349177555,
989+
"y": 0.6976311549107443
990990
},
991991
"Ealing": {
992-
"x": 0.5400420961248721,
993-
"y": 0.21038571486656277
992+
"x": 0.625347640578031,
993+
"y": 0.6317978790367245
994994
},
995995
"Havering": {
996-
"x": 0.1688240674546505,
997-
"y": 0.5761502829303673
996+
"x": 0.3108678700595878,
997+
"y": 0.22621673610904275
998998
},
999999
"Hillingdon": {
1000-
"x": 0.6354038702339622,
1001-
"y": 0.22199528810234076
1000+
"x": 0.6022222665632444,
1001+
"y": 0.7222515410131087
10021002
},
10031003
"Harrow": {
1004-
"x": 0.524001228362884,
1005-
"y": 0.13522079896180383
1004+
"x": 0.7005252293406612,
1005+
"y": 0.6189981770800439
10061006
},
10071007
"Brent": {
1008-
"x": 0.48147870675137133,
1009-
"y": 0.2679823299914469
1008+
"x": 0.587842113690193,
1009+
"y": 0.5617185665997343
10101010
},
10111011
"Barnet": {
1012-
"x": 0.38578686527417094,
1013-
"y": 0.2167513696913214
1012+
"x": 0.6370161435385779,
1013+
"y": 0.47173892603128303
10141014
},
10151015
"Lambeth": {
1016-
"x": 0.46627295137128183,
1017-
"y": 0.4275032324546504
1016+
"x": 0.4278996905373078,
1017+
"y": 0.5247623262642699
10181018
},
10191019
"Southwark": {
1020-
"x": 0.4175404112925465,
1021-
"y": 0.4125947258251618
1020+
"x": 0.4432484582198962,
1021+
"y": 0.48182299704680825
10221022
},
10231023
"Lewisham": {
1024-
"x": 0.4366510973802941,
1025-
"y": 0.5364340597763461
1024+
"x": 0.32110013392304354,
1025+
"y": 0.48632865185588714
10261026
},
10271027
"Greenwich": {
1028-
"x": 0.36228512193363693,
1029-
"y": 0.5346378307922829
1028+
"x": 0.32696022143450215,
1029+
"y": 0.41608744633944383
10301030
},
10311031
"Bexley": {
1032-
"x": 0.243231285319052,
1033-
"y": 0.5294030043746105
1032+
"x": 0.33846947961311447,
1033+
"y": 0.30028202109155017
10341034
},
10351035
"Enfield": {
1036-
"x": 0.22900240838964434,
1037-
"y": 0.19810613153001336
1036+
"x": 0.678814354075708,
1037+
"y": 0.32393220755723784
10381038
},
10391039
"Waltham Forest": {
1040-
"x": 0.21184381142819164,
1041-
"y": 0.3195206944124669
1040+
"x": 0.5373137162405288,
1041+
"y": 0.2953047884931445
10421042
},
10431043
"Redbridge": {
1044-
"x": 0.31181754014966806,
1045-
"y": 0.44501084181283607
1044+
"x": 0.4157675701237338,
1045+
"y": 0.3679994709500549
10461046
},
10471047
"Sutton": {
1048-
"x": 0.6575109745368094,
1049-
"y": 0.4127833424469328
1048+
"x": 0.4130166771531945,
1049+
"y": 0.7181224568597673
10501050
},
10511051
"Richmond upon Thames": {
1052-
"x": 0.6022702513151891,
1053-
"y": 0.3294127821234389
1052+
"x": 0.4815182986244713,
1053+
"y": 0.6640572155013125
10541054
},
10551055
"Merton": {
1056-
"x": 0.5828905412068713,
1057-
"y": 0.4325437504552626
1056+
"x": 0.3978753391255891,
1057+
"y": 0.653465949882818
10581058
},
10591059
"Wandsworth": {
1060-
"x": 0.5584088670546962,
1061-
"y": 0.41681985555811396
1060+
"x": 0.4189235411771941,
1061+
"y": 0.6382500256522735
10621062
},
10631063
"Hammersmith and Fulham": {
1064-
"x": 0.5402191612572013,
1065-
"y": 0.3064493391608021
1064+
"x": 0.5308542721995256,
1065+
"y": 0.6133024551865476
10661066
},
10671067
"Kensington and Chelsea": {
1068-
"x": 0.5366403592727638,
1069-
"y": 0.3375332979644655
1068+
"x": 0.4943886606353542,
1069+
"y": 0.6007135551203813
10701070
},
10711071
"Westminster": {
1072-
"x": 0.4569576032655334,
1073-
"y": 0.33448965619975907
1072+
"x": 0.511310569005366,
1073+
"y": 0.510598968935623
10741074
},
10751075
"Camden": {
1076-
"x": 0.416802337087345,
1077-
"y": 0.3387650855632808
1076+
"x": 0.5157842986656155,
1077+
"y": 0.48310587540075706
10781078
},
10791079
"Tower Hamlets": {
1080-
"x": 0.330614551457683,
1081-
"y": 0.43609211768718675
1080+
"x": 0.43122221547909606,
1081+
"y": 0.40714919111788905
10821082
},
10831083
"Islington": {
1084-
"x": 0.3556582179458492,
1085-
"y": 0.3152623432121067
1084+
"x": 0.5539109490250118,
1085+
"y": 0.4419128236965202
10861086
},
10871087
"Hackney": {
1088-
"x": 0.29079176262429074,
1089-
"y": 0.3578168744972754
1088+
"x": 0.5116566309321687,
1089+
"y": 0.3609320177315044
10901090
},
10911091
"Haringey": {
1092-
"x": 0.2892693134358225,
1093-
"y": 0.268500916846826
1092+
"x": 0.6056592172779078,
1093+
"y": 0.37915729947595783
10941094
},
10951095
"Newham": {
1096-
"x": 0.2372900221144474,
1097-
"y": 0.4667112092931355
1096+
"x": 0.4252125049060929,
1097+
"y": 0.30405341610599906
10981098
},
10991099
"Barking and Dagenham": {
1100-
"x": 0.26221470962251936,
1101-
"y": 0.5643895639350828
1100+
"x": 0.3088003820213305,
1101+
"y": 0.30479349262432553
11021102
},
11031103
"City of London": {
1104-
"x": 0.3762839873327546,
1105-
"y": 0.37292082525266146
1104+
"x": 0.4848819109101783,
1105+
"y": 0.45398054813737043
11061106
}
11071107
}
11081108
}

0 commit comments

Comments
 (0)