
proc ShowMethOptions {} {
    global WDMethOpt InternalWindowing DialogFrame

    if {$InternalWindowing} {
        set WDMethOpt $DialogFrame.methopt
        if {![winfo exists $WDMethOpt]} {
            frame $WDMethOpt -width 230 -height 520
            pack propagate $WDMethOpt false
        }
        
        RegisterDialog "Method Options" $WDMethOpt ShowMethOptions {}
    } else {
        set WDMethOpt .methopt
        if {![winfo exists $WDMethOpt]} {
            toplevel $WDMethOpt
            wm geometry $WDMethOpt 280x540
            wm resizable $WDMethOpt 0 0
        }
    }
    
    DisplayBasicOptions

    if {$InternalWindowing} {
        pack $WDMethOpt -anchor nw
        AlignActiveDialog
    }
}


proc DisplayBasicOptions {} {
    global WDMethOpt DefPadX DefPadY InternalWindowing

    if {!$InternalWindowing} {wm title $WDMethOpt "GOBLIN Method Options"}

    destroy $WDMethOpt.buttons
    frame $WDMethOpt.buttons
    button $WDMethOpt.buttons.done -text "Done" -command { \
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDMethOpt
        }
    }
    
    button $WDMethOpt.buttons.prev -text back \
        -command DisplayLPOptions
    
    button $WDMethOpt.buttons.next -text more \
        -command DisplayNetworkFlowOptions
    
    pack $WDMethOpt.buttons.prev $WDMethOpt.buttons.next $WDMethOpt.buttons.done \
        -side left -fill x -padx 3m
     
    pack $WDMethOpt.buttons -padx 3m -pady 3m -side bottom

    destroy $WDMethOpt.options
    frame $WDMethOpt.options
    pack $WDMethOpt.options -fill both -padx $DefPadX -pady $DefPadY

    frame $WDMethOpt.options.search
    frame $WDMethOpt.options.tree
    frame $WDMethOpt.options.1tree
    frame $WDMethOpt.options.maxFlow
    pack $WDMethOpt.options.search $WDMethOpt.options.tree $WDMethOpt.options.1tree \
        $WDMethOpt.options.maxFlow -side top -fill x -pady 5m
        
    label $WDMethOpt.options.search.label -text "Shortest Paths:" -anchor w
    radiobutton $WDMethOpt.options.search.fifo -text "FIFO Label Correcting" \
        -variable goblinMethSearch -value 0 -anchor w
    radiobutton $WDMethOpt.options.search.dijkstra -text "Dijkstra" \
        -variable goblinMethSearch -value 1 -anchor w
    radiobutton $WDMethOpt.options.search.bellman -text "Bellman/Ford" \
        -variable goblinMethSearch -value 2 -anchor w
    radiobutton $WDMethOpt.options.search.bfs -text "BFS" \
        -variable goblinMethSearch -value 3 -anchor w
    pack $WDMethOpt.options.search.label \
        $WDMethOpt.options.search.fifo \
        $WDMethOpt.options.search.dijkstra \
        $WDMethOpt.options.search.bellman \
        $WDMethOpt.options.search.bfs \
        -fill x
        
    label $WDMethOpt.options.tree.label -text "Minimum Spanning Trees:" -anchor w
    radiobutton $WDMethOpt.options.tree.prim -text "Prim" \
        -variable goblinMethMinTree -value 0 -anchor w
    radiobutton $WDMethOpt.options.tree.enhanced -text "Enhanced Prim" \
        -variable goblinMethMinTree -value 1 -anchor w
    radiobutton $WDMethOpt.options.tree.kruskal -text "Kruskal" \
        -variable goblinMethMinTree -value 2 -anchor w
    pack $WDMethOpt.options.tree.label \
        $WDMethOpt.options.tree.prim \
        $WDMethOpt.options.tree.enhanced \
        $WDMethOpt.options.tree.kruskal \
        -fill x

    checkbutton $WDMethOpt.options.1tree.check \
        -text "Compute 1-Trees" -variable goblinMeth1Tree -anchor w
    pack $WDMethOpt.options.1tree.check -fill x

    label $WDMethOpt.options.maxFlow.label -text "Maximum st-Flows:" -anchor w
    radiobutton $WDMethOpt.options.maxFlow.successive -text "Successive Augmentation" \
        -variable goblinMethMaxFlow -value 0 -anchor w
    radiobutton $WDMethOpt.options.maxFlow.dinic -text "Dinic" \
        -variable goblinMethMaxFlow -value 1 -anchor w
    radiobutton $WDMethOpt.options.maxFlow.fifo -text "Push/Relabel (FIFO)" \
        -variable goblinMethMaxFlow -value 2 -anchor w
    radiobutton $WDMethOpt.options.maxFlow.highest -text "Push/Relabel (Highest Label)" \
        -variable goblinMethMaxFlow -value 3 -anchor w
    radiobutton $WDMethOpt.options.maxFlow.scaling -text "Capacity Scaling" \
        -variable goblinMethMaxFlow -value 4 -anchor w
    pack $WDMethOpt.options.maxFlow.label \
        $WDMethOpt.options.maxFlow.successive \
        $WDMethOpt.options.maxFlow.dinic \
        $WDMethOpt.options.maxFlow.fifo \
        $WDMethOpt.options.maxFlow.highest \
        $WDMethOpt.options.maxFlow.scaling \
        -fill x
}        


proc DisplayNetworkFlowOptions {} {
    global WDMethOpt DefPadX DefPadY InternalWindowing

    if {!$InternalWindowing} {wm title $WDMethOpt "GOBLIN Min-Cost Flow Options"}

    destroy $WDMethOpt.buttons
    frame $WDMethOpt.buttons
    button $WDMethOpt.buttons.done -text "Done" -command { \
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDMethOpt
        }
    }
    
    button $WDMethOpt.buttons.prev -text back \
        -command DisplayBasicOptions
    
    button $WDMethOpt.buttons.next -text more \
        -command DisplayMatchingOptions
    
    pack $WDMethOpt.buttons.prev $WDMethOpt.buttons.next $WDMethOpt.buttons.done \
        -side left -fill x -padx 3m
     
    pack $WDMethOpt.buttons -padx 3m -pady 3m -side bottom

    destroy $WDMethOpt.options
    frame $WDMethOpt.options -width 260 -height 520
    pack $WDMethOpt.options -fill both -padx $DefPadX -pady $DefPadY

    frame $WDMethOpt.options.minCFlow
    frame $WDMethOpt.options.minCCirc
    frame $WDMethOpt.options.checkButtons
    pack $WDMethOpt.options.minCFlow \
        $WDMethOpt.options.minCCirc $WDMethOpt.options.checkButtons -side top -fill x -pady 5m
        
    label $WDMethOpt.options.minCFlow.label -text "Min Cost st-Flows:" -anchor w
    radiobutton $WDMethOpt.options.minCFlow.revised -text "Revised SAP" \
        -variable goblinMethMinCFlow -value 0 -anchor w
    radiobutton $WDMethOpt.options.minCFlow.sap -text "Successive Augmentation" \
        -variable goblinMethMinCFlow -value 1 -anchor w
    radiobutton $WDMethOpt.options.minCFlow.transform -text "Transform to b-flow" \
        -variable goblinMethMinCFlow -value 3 -anchor w
    pack $WDMethOpt.options.minCFlow.label \
        $WDMethOpt.options.minCFlow.sap \
        $WDMethOpt.options.minCFlow.revised \
        $WDMethOpt.options.minCFlow.transform \
        -fill x
        
    label $WDMethOpt.options.minCCirc.label -text "Min Cost b-Flows:" -anchor w
    radiobutton $WDMethOpt.options.minCCirc.klein -text "Klein" \
        -variable goblinMethMinCCirc -value 0 -anchor w
    radiobutton $WDMethOpt.options.minCCirc.scaling -text "Cost Scaling" \
        -variable goblinMethMinCCirc -value 1 -anchor w
    radiobutton $WDMethOpt.options.minCCirc.tighten -text "Enhanced Cost Scaling" \
        -variable goblinMethMinCCirc -value 2 -anchor w
    radiobutton $WDMethOpt.options.minCCirc.mean -text "Minimum Mean Cycles" \
        -variable goblinMethMinCCirc -value 3 -anchor w
    radiobutton $WDMethOpt.options.minCCirc.transform -text "Transform to st-Flow" \
        -variable goblinMethMinCCirc -value 4 -anchor w
    radiobutton $WDMethOpt.options.minCCirc.nwsimplex -text "Primal Network Simplex" \
        -variable goblinMethMinCCirc -value 5 -anchor w
    radiobutton $WDMethOpt.options.minCCirc.lpsolve -text "Reduction to LP" \
        -variable goblinMethMinCCirc -value 6 -anchor w
    pack $WDMethOpt.options.minCCirc.label \
        $WDMethOpt.options.minCCirc.klein \
        $WDMethOpt.options.minCCirc.scaling \
        $WDMethOpt.options.minCCirc.tighten \
        $WDMethOpt.options.minCCirc.mean \
        $WDMethOpt.options.minCCirc.nwsimplex \
        $WDMethOpt.options.minCCirc.lpsolve \
        $WDMethOpt.options.minCCirc.transform \
        -fill x

    checkbutton $WDMethOpt.options.checkButtons.failSave \
        -text "Check reduced cost optimality" -variable goblinMethFailSave -anchor w
    pack $WDMethOpt.options.checkButtons.failSave -fill x
}
        
     
proc DisplayMatchingOptions {} {
    global WDMethOpt DefPadX DefPadY InternalWindowing

    if {!$InternalWindowing} {wm title $WDMethOpt "GOBLIN Matching Options"}

    destroy $WDMethOpt.buttons
    frame $WDMethOpt.buttons
    button $WDMethOpt.buttons.done -text "Done" -command { \
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDMethOpt
        }
    }
    
    button $WDMethOpt.buttons.prev -text "back" \
        -command DisplayNetworkFlowOptions
    
    button $WDMethOpt.buttons.next -text "more" \
        -command DisplayLPOptions
    
    pack $WDMethOpt.buttons.prev $WDMethOpt.buttons.next $WDMethOpt.buttons.done \
        -side left -fill x -padx 3m
     
    pack $WDMethOpt.buttons -padx 3m -pady 3m -side bottom

    destroy $WDMethOpt.options
    frame $WDMethOpt.options
    pack $WDMethOpt.options -fill both -padx $DefPadX -pady $DefPadY

    frame $WDMethOpt.options.maxBalFlow
    frame $WDMethOpt.options.bns
    frame $WDMethOpt.options.checkButtons
    pack $WDMethOpt.options.maxBalFlow $WDMethOpt.options.bns \
        $WDMethOpt.options.checkButtons -side top -fill x -pady 5m
        
    label $WDMethOpt.options.maxBalFlow.label -text "Non-Weighted Matching:" -anchor w
    radiobutton $WDMethOpt.options.maxBalFlow.successive -text "Successive Augmentation" \
        -variable goblinMethMaxBalFlow -value 0 -anchor w
    radiobutton $WDMethOpt.options.maxBalFlow.phase -text "Phase Ordered Augmentation" \
        -variable goblinMethMaxBalFlow -value 1 -anchor w
    radiobutton $WDMethOpt.options.maxBalFlow.look -text "... with Lookahead Operations" \
        -variable goblinMethMaxBalFlow -value 2 -anchor w
    radiobutton $WDMethOpt.options.maxBalFlow.look2 -text "... with Simple Augmentations" \
        -variable goblinMethMaxBalFlow -value 3 -anchor w
    radiobutton $WDMethOpt.options.maxBalFlow.scaling -text "Capacity Scaling" \
        -variable goblinMethMaxBalFlow -value 4 -anchor w
    radiobutton $WDMethOpt.options.maxBalFlow.maxflow -text "Start with Maximum Flow" \
        -variable goblinMethMaxBalFlow -value 5 -anchor w
    pack $WDMethOpt.options.maxBalFlow.label \
        $WDMethOpt.options.maxBalFlow.successive \
        $WDMethOpt.options.maxBalFlow.phase \
        $WDMethOpt.options.maxBalFlow.look \
        $WDMethOpt.options.maxBalFlow.look2 \
        $WDMethOpt.options.maxBalFlow.scaling \
        $WDMethOpt.options.maxBalFlow.maxflow \
        -fill x
        
    label $WDMethOpt.options.bns.label -text "Balanced Network Search:" -anchor w
    radiobutton $WDMethOpt.options.bns.exact -text "Exact Search" \
        -variable goblinMethBNS -value 0 -anchor w
    radiobutton $WDMethOpt.options.bns.dfs1 -text "Depth First Heuristics 1" \
        -variable goblinMethBNS -value 1 -anchor w
    radiobutton $WDMethOpt.options.bns.dfs2 -text "Depth First Heuristics 2" \
        -variable goblinMethBNS -value 2 -anchor w
    radiobutton $WDMethOpt.options.bns.bfs -text "Breadth First Heuristics" \
        -variable goblinMethBNS -value 3 -anchor w
    pack $WDMethOpt.options.bns.label \
        $WDMethOpt.options.bns.exact \
        $WDMethOpt.options.bns.dfs1 \
        $WDMethOpt.options.bns.dfs2 \
        $WDMethOpt.options.bns.bfs \
        -fill x
        
    label $WDMethOpt.options.checkButtons.label -text "Weighted Matching:" -anchor w
    checkbutton $WDMethOpt.options.checkButtons.enhanced \
        -text "Start with Min Cost Flow" \
        -variable goblinMethMinCBalFlow -anchor w
    checkbutton $WDMethOpt.options.checkButtons.explicit \
        -text "Explicit Reduced Length Labels" \
        -variable goblinMethModLength -anchor w
    pack $WDMethOpt.options.checkButtons.label \
        $WDMethOpt.options.checkButtons.enhanced \
        $WDMethOpt.options.checkButtons.explicit -fill x
}


proc DisplayLPOptions {} {
    global WDMethOpt DefPadX DefPadY InternalWindowing

    if {!$InternalWindowing} {wm title $WDMethOpt "GOBLIN Linear Programming Options"}

    destroy $WDMethOpt.buttons
    frame $WDMethOpt.buttons
    button $WDMethOpt.buttons.done -text "Done" -command { \
        if {$InternalWindowing} {
            DestroyActiveDialog
        } else {
            destroy $WDMethOpt
        }
    }

    button $WDMethOpt.buttons.prev -text back \
        -command DisplayMatchingOptions
    
    button $WDMethOpt.buttons.next -text more \
        -command DisplayBasicOptions
    
    pack $WDMethOpt.buttons.prev $WDMethOpt.buttons.next $WDMethOpt.buttons.done \
        -side left -fill x -padx 3m
     
    pack $WDMethOpt.buttons -padx 3m -pady 3m -side bottom

    destroy $WDMethOpt.options
    frame $WDMethOpt.options
    pack $WDMethOpt.options -fill both -padx $DefPadX -pady $DefPadY

    frame $WDMethOpt.options.lp
    frame $WDMethOpt.options.mip
    pack $WDMethOpt.options.lp $WDMethOpt.options.mip -side top -fill x -pady 5m
        
    label $WDMethOpt.options.lp.label -text "Linear Programming:" -anchor w
    radiobutton $WDMethOpt.options.lp.auto -text "Automatic" \
        -variable goblinMethLP -value 0 -anchor w
    radiobutton $WDMethOpt.options.lp.primal -text "Primal Simplex" \
        -variable goblinMethLP -value 1 -anchor w
    radiobutton $WDMethOpt.options.lp.dual -text "Dual Simplex" \
        -variable goblinMethLP -value 2 -anchor w
    pack $WDMethOpt.options.lp.label \
        $WDMethOpt.options.lp.auto \
        $WDMethOpt.options.lp.primal \
        $WDMethOpt.options.lp.dual \
        -fill x
        
    label $WDMethOpt.options.mip.label -text "Mixed Integer Programming:" -anchor w
    radiobutton $WDMethOpt.options.mip.branchNBound -text "Branch and Bound" \
        -variable goblinMethMIP -value 0 -anchor w -state disabled
    radiobutton $WDMethOpt.options.mip.cutting -text "Cutting Planes" \
        -variable goblinMethMIP -value 1 -anchor w -state disabled
    radiobutton $WDMethOpt.options.mip.branchNCut -text "Branch and Cut" \
        -variable goblinMethMIP -value 2 -anchor w -state disabled
    pack $WDMethOpt.options.mip.label \
        $WDMethOpt.options.mip.branchNBound \
        $WDMethOpt.options.mip.cutting \
        $WDMethOpt.options.mip.branchNCut \
        -fill x
}


global WDMethOpt
if {![info exists WDMethOpt] || ![winfo exists $WDMethOpt]} {ShowMethOptions}
