--File: IPPlaceProcsImpl.mesa
Last Edited by: CSChow, January 25, 1985 12:34:38 pm PST
DIRECTORY
OrderedRefArray,
IPCoTab,
IPTop,
IPTopOps,
IPPlaceKit,
IPPlaceProcs;
IPPlaceProcsImpl: CEDAR PROGRAM
IMPORTS OrderedRefArray, IPCoTab, IPTop, IPTopOps, IPPlaceKit
EXPORTS IPPlaceProcs = BEGIN OPEN IPPlaceProcs;
PlaceInit: PUBLIC PROC [
top: IPTop.Ref,
orderingFn: IPPlaceKit.OrderingFn,
trialsGen: IPPlaceKit.PlaceCompTGen,
placeEval: IPPlaceKit.PlaceEvaluator,
results: OrderedRefArray.Ref] ={
comps: IPPlaceKit.Components;
depthAndBreadthList: LIST OF IPPlaceKit.DepthBreadthRec;
placeRecursively: PROC[comps: IPPlaceKit.Components, dbList: LIST OF IPPlaceKit.DepthBreadthRec, prevStkSize: NAT] ={
dAndb: IPPlaceKit.DepthBreadthRec ← dbList.first;
compsHd: IPPlaceKit.Components;
IF placeEval[top, comps, OrderedRefArray.GetPruneValue[results]].prune THEN RETURN;
[compsHd, comps] ← IPPlaceKit.CopyCompsHead[comps, dAndb.depth];
dbList ← dbList.rest;
IF comps = NIL OR dbList.first.depth = 0
THEN PlaceComps[top, compsHd, trialsGen, placeEval, results, 0]
ELSE {
trials: OrderedRefArray.Ref ← OrderedRefArray.Create[dAndb.breadth];
eachTrialAction: OrderedRefArray.EachItemAction ={
IPTopOps.Redo[top, NARROW[item]];
placeRecursively[comps, dbList, IPTopOps.StackSize[top]];
[] ← IPTopOps.Undo[top, IPTopOps.StackSize[top] - prevStkSize]; --undo Redo
}; --eachTrialAction
PlaceComps[top, compsHd, trialsGen, placeEval, trials, prevStkSize];
OrderedRefArray.Enumerate[trials, eachTrialAction];
};
}; --placeRecursively
--(1) Order the nonActive components in placement order
[comps, depthAndBreadthList] ← orderingFn[top];
--(2) If assembly has no channels define channels, insert a component if necessary
IF IPTop.NoTopology[top] THEN {
IF IPCoTab.CountComponents[top.coTab].active = 0
THEN [] ← IPTopOps.SetComponent[top, comps.first, TRUE, [0,0], TRUE];
[] ← IPTop.ReDefineChs[top];
IPTop.Geometrize[top];
comps ← comps.rest;
depthAndBreadthList.first.depth ← depthAndBreadthList.first.depth.PRED
};
--(3) Do placement recursively
placeRecursively[comps, depthAndBreadthList, IPTopOps.StackSize[top]];
}; --PlaceInit
PlaceImprove: PUBLIC PROC[
top: IPTop.Ref,
remove,
numbOfTrials: NAT,
removeTGen: IPPlaceKit.RemoveCompTGen,
removeEval: IPPlaceKit.RemoveEvaluator,
placeTGen: IPPlaceKit.PlaceCompTGen,
placeEval: IPPlaceKit.PlaceEvaluator,
results: OrderedRefArray.Ref
] = {
startStkSize: NAT ← IPTopOps.StackSize[top];
removalTrials: OrderedRefArray.Ref ← OrderedRefArray.Create[numbOfTrials];
eachRemoveTrialAction: OrderedRefArray.EachItemAction ={
track: LIST OF REFNARROW[item];
comps: IPPlaceKit.Components ← IPPlaceKit.GetComponents[track];
IPTopOps.Redo[top, track];
IF placeEval[top, comps, OrderedRefArray.GetPruneValue[results]].prune
THEN NULL
ELSE PlaceComps[top, comps, placeTGen, placeEval, results, 0];
[] ← IPTopOps.Undo[top, IPTopOps.StackSize[top] - startStkSize];
}; --eachRemoveTrialAction
--(1) Remove the needed number of components
RemoveComps[top, remove, removeTGen, removeEval, removalTrials, startStkSize];
--(2) Try PlaceComps on each remove trial
OrderedRefArray.Enumerate[removalTrials, eachRemoveTrialAction];
}; --PlaceImprove
PlaceComps: PUBLIC PROC[top: IPTop.Ref, comps: LIST OF IPCoTab.Component, trialsGen: IPPlaceKit.PlaceCompTGen, placeEval: IPPlaceKit.PlaceEvaluator, results: OrderedRefArray.Ref, resultsAfter: NAT] = {
startStkSize: NAT ← IPTopOps.StackSize[top];
trials: OrderedRefArray.Ref ← trialsGen[top, comps];
eachTrialAction: OrderedRefArray.EachItemAction ={
IPPlaceKit.Execute[top, item];
IF comps = NIL
THEN OrderedRefArray.Insert[results, IPTopOps.GetTrack[top, resultsAfter], placeEval[top, NIL].value]
ELSE
IF placeEval[top, comps, OrderedRefArray.GetPruneValue[results]].prune
THEN NULL --not fruitful
ELSE PlaceComps[top, comps, trialsGen, placeEval, results, resultsAfter];
[] ← IPTopOps.Undo[top, IPTopOps.StackSize[top] - startStkSize];
}; --eachTrialAction
comps ← comps.rest;
OrderedRefArray.Enumerate[trials, eachTrialAction]
}; --PlaceComps
RemoveComps: PUBLIC PROC[
top: IPTop.Ref,
numb: NAT,
trialsGen: IPPlaceKit.RemoveCompTGen,
removeEval: IPPlaceKit.RemoveEvaluator,
results: OrderedRefArray.Ref,
resultsAfter: NAT ← 0
] ={
startStkSize: NAT ← IPTopOps.StackSize[top];
trials: OrderedRefArray.Ref ← trialsGen[top, numb];
eachTrialAction: OrderedRefArray.EachItemAction ={
IPPlaceKit.Execute[top, item];
IF numb = 0
THEN OrderedRefArray.Insert[results, IPTopOps.GetTrack[top, resultsAfter], removeEval[top, 0].value]
ELSE
IF removeEval[top, numb, OrderedRefArray.GetPruneValue[results]].prune
THEN NULL
ELSE RemoveComps[top, numb, trialsGen, removeEval, results, resultsAfter];
[] ← IPTopOps.Undo[top, IPTopOps.StackSize[top] - startStkSize];
}; --eachTrialAction
numb ← numb.PRED;
OrderedRefArray.Enumerate[trials, eachTrialAction]
}; --RemoveComps
END.