SAPlace:
PUBLIC
PROCEDURE [handle:
SC.Handle, t0, alpha:
REAL, seed:
INT] = {
Freezing:
PROCEDURE [score:
REAL, temprature:
REAL]
RETURNS [
BOOLEAN] = {
RETURN[TRUE]};
Equilibrium:
PROCEDURE [score:
REAL]
RETURNS [
BOOLEAN] = {
RETURN[TRUE]};
Select:
PROCEDURE []
RETURNS [exch: ExchDescription ← [
NIL,
NIL]] = {
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
numInstances: SCPrivate.ZMaxInstanceSr ← structureData.instances.count;
numLogics: SCPrivate.ZMaxInstanceSr ← structureData.instances.numLogics;
numIOs: SCPrivate.ZMaxInstanceSr ← structureData.instances.numIOs;
inst1: SCPrivate.Instance ← GetInstance[];
inst2: SCPrivate.Instance;
IF inst1.whichClass = io
THEN {
got an IO, get another IO
IF inst1 = NIL THEN RETURN
ELSE {
inst2 ← GetIo[inst1];
IF inst2 = NIL THEN RETURN}}
ELSE
IF inst1.whichClass = logic
THEN {
got a logic, get another logic
IF inst1 = NIL THEN RETURN
ELSE {
inst2 ← GetLogic[inst1];
IF inst2 = NIL THEN RETURN}}
ELSE SC.Error[programmingError, "Invalid instance index"];
RETURN[[inst1, inst2]]};
GetInstance:
PROCEDURE []
RETURNS [instance: SCPrivate.Instance ←
NIL]= {
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
numInstances: SCPrivate.ZMaxInstanceSr ← structureData.instances.count;
index: SCPrivate.ZMaxInstanceSr ← Random.ChooseInt[selectStream, 1, numInstances];
instance ← structureData.instances.inst[index];
RETURN[instance]};
NextInstanceIndex:
PROCEDURE [inst1: SCPrivate.Instance]
RETURNS [inst2: SCPrivate.Instance ←
NIL]= {
RETURN[inst2]};
GetIo:
PROCEDURE [inst1: SCPrivate.Instance]
RETURNS [inst2: SCPrivate.Instance ←
NIL]= {
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
numInstances: SCPrivate.ZMaxInstanceSr ← structureData.instances.count;
numLogics: SCPrivate.ZMaxInstanceSr ← structureData.instances.numLogics;
numIOs: SCPrivate.ZMaxInstanceSr ← structureData.instances.numIOs;
index: SCPrivate.ZMaxInstanceSr ← Random.ChooseInt[selectStream, 1, numInstances];
FOR i: SCPrivate.Instance ← NextInstanceIndex[inst1], NextInstanceIndex[i]
WHILE i # inst1
AND inst2 =
NIL
DO
ENDLOOP;
RETURN[inst2]};
GetLogic:
PROCEDURE [inst1: SCPrivate.Instance]
RETURNS [inst2: SCPrivate.Instance ←
NIL]= {
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
numIOs: SCPrivate.ZMaxInstanceSr ← structureData.instances.numIOs;
logicIndex: SCPrivate.ZMaxInstanceSr ← index - numIOs;
numInstances: SCPrivate.ZMaxInstanceSr ← structureData.instances.count;
index: SCPrivate.ZMaxInstanceSr ← Random.ChooseInt[selectStream, numIOs + 1, numInstances];
RETURN[inst2]};
Exchange:
PROCEDURE [exch: ExchDescription]
RETURNS [didIt:
BOOLEAN ←
TRUE] = {
};
FullScore:
PROCEDURE [handle:
SC.Handle]
RETURNS [score:
REAL] = {
RETURN[score]};
ModScore:
PROCEDURE [exch: ExchDescription]
RETURNS [score:
REAL]= {
RETURN[score]};
Random0To1:
PROCEDURE []
RETURNS [value:
REAL]= {
RETURN[Real.Float[Random.ChooseInt[choiceStream, 0, 100000]]/100000.0]};
layoutData: SCPrivate.LayoutData ← NARROW[handle.layoutData];
structureData: SCPrivate.StructureData ← NARROW[handle.structureData];
lgRows: SCPrivate.LgRows ← layoutData.lgRows;
selectStream: Random.RandomStream ← Random.Create[LAST[INT], seed];
choiceStream: Random.RandomStream ← Random.Create[LAST[INT], seed];
startArea: SC.Number;
temprature: REAL ← t0;
score: REAL ← FullScore[handle];
[lgRows.maxRowWidth, lgRows.numMaxRows] ← SCRowUtil.FindMaxRow[handle];
SCWidthUtil.AllChanWidths[handle, areaFom];
SCInstUtil.AsgnChanPos[handle];
startArea ← SCUtil.WriteResults["Position improvement\n starting area:", handle, 0];
UNTIL Freezing[score, temprature]
DO
UNTIL Equilibrium[score]
DO
exch: ExchDescription ← Select[];
IF Exchange[exch]
THEN {
trialScore: REAL ← ModScore[exch];
deltaScore: REAL ← trialScore - score;
IF deltaScore < 0.0 THEN score ← trialScore
ELSE {
random: REAL ← Random0To1[];
IF random < RealFns.Exp[-deltaScore/temprature]
THEN {
[] ← Exchange[exch]}}};
ENDLOOP;
temprature ← alpha * temprature;
ENDLOOP;
SCInstUtil.AllOffsets[handle];
[lgRows.maxRowWidth, lgRows.numMaxRows] ← SCRowUtil.FindMaxRow[handle];
SCWidthUtil.AllChanWidths[handle, areaFom];
SCInstUtil.AsgnChanPos[handle];
[] ← SCUtil.WriteResults["End position improvement\n ending area:", handle, startArea];
IF debug THEN SCPlaceUtil.WriteCurPlace[handle]};
}.