type Node<'T> = { Value : 'T; Next : Node<'T> option }
let mutable First : Node<'T> option = None
First <- Some { Value = item; Next = oldFirst }
member x.Size with get() = N
let rec PrintLoop (node: Node<'T> option) =
type Coordinate = ( int * int)
type Location = ( string * Coordinate )
type Bounds = ( int * int )
let AllLocations : Location list =
("Bristol" , (0,0)):: ("London", (200, 20)) :: ("Oxford",(180, 70))::("Birmingham",(130,120))::("Wolverhampton",(120,120))::("Tewkesbury",(10,100))::("Manchester",(10,200))::
("Carlisle",(30,300))::("Glasgow",(40,400))::("Edinburgh",(50,400))::[]
type Solution = (Location option * Location option * Location option *
Location option * Location option * Location option *
Location option * Location option * Location option *
Location option * Location list)
type PartialSolution = Location option list
type Soln2 = (PartialSolution * NextChange)
let Some (a , b, c, d, e, f, g, h,i,j, unallocated) = solution
let compare newBestEstimateSoFar bestEstimateSoFar =
newBestEstimateSoFar < bestEstimateSoFar
let splitCalcs (stack : Stack<'T>) solution =
let (a , b, c, d, e, f, g, h,i,j, unallocated) = solution
| None -> stack.Push solution
| Some (locn,(x,y)) -> stack.Push solution
let initialSolution : Solution =
(Some ("London",(200,20)), Some ("Bristol" , (0,0)) , Some ("Oxford",(180, 70)), Some ("Birmingham",(130,120)), Some("Wolverhampton",(120,120)), Some ("Tewkesbury",(10,100)), Some("Manchester",(10,200)), Some ("Carlisle",(30,300)), Some ("Glasgow",(40,400)), Some ("Edinburgh",(50,400)) , [])
let initialEstimate = 1 + (estimate initialSolution)
let chooseLowerEstimate thisEstimate bestEstimate =
match (compare thisEstimate bestEstimate) with
| true -> (thisEstimate, true)
| false -> (bestEstimate, false)
let rec minimise (stack: Stack<'T>) bestSolutionSoFar bestEstimateSoFar =
let topSolution = stack.Pop()
| None -> ( bestSolutionSoFar, bestEstimateSoFar )
let thisEstimate = estimate solution
let (newBestEstimateSoFar, newIsBetter) =
chooseLowerEstimate thisEstimate bestEstimateSoFar
splitCalcs stack solution
minimise stack solution newBestEstimateSoFar
minimise stack bestSolutionSoFar bestEstimateSoFar
let stak = Stack<Solution>()
stak.Push(initialSolution)
let bestSolution = minimise stak initialSolution initialEstimate
printfn "%A " bestSolution