Академический Документы
Профессиональный Документы
Культура Документы
1000) As Variant Global loc_matrix(1000, 1000) As Variant Global C(1000, 1000), x(1000, 1000) As Variant Global rc, DC, TC, AC, W1, W2 As Double Global initTC, pairwisetemp As Variant Global randtp, randrow1, randrow2, randcol1, randcol2 As Integer Global iterations As Integer Global pherome(1000, 1000), Pt, q, a1, a2 As Double
Private Sub Command1_Click() On Error Resume Next If Not IsNumeric(Text1) Or Not IsNumeric(Text2) Or Not IsNumeric(Text3) Or Not IsNumeric(Text4) Or Not IsNumeric(Text5) Then MsgBox ("Enter Numeric Values for all Fields") Exit Sub End If dpt = CInt(Text1.Text) rc = CDbl(Text2.Text) tp = CInt(Text3.Text) W1 = CDbl(Text4.Text) W2 = CDbl(Text5.Text) q = CDbl(Text6.Text) a1 = CDbl(Text7.Text) a2 = CDbl(Text8.Text)
Command1.Visible = False
End Sub
Private Sub exit_Click() End End Sub Private Sub closeness_Click() frmcloseness.Show End Sub
End Sub
Private Sub improve_Click() Randomize ' randomly pick a time period and then improve the layout 'check if the TC is less before you accept randtp = CInt(Int(Rnd() * tp) + 1) 'choose the random period randrow = CInt(Int(Rnd() * dpt) + 1) 'choose the random row to swap
Dim initAC, initDC As Double initTC = TC ' initial TC is noted initAC = AC initDC = DC
iterations = dpt * dpt * tp ' N *N *T R = dpt * dpt * tp Dim thecount As Integer For thecount = 1 To iterations randrow1 = CInt(Int(Rnd() * dpt) + 1) 'choose the random row to swap randcol1 = CInt(Int(Rnd() * dpt) + 1) 'choose the random col to swap
randrow2 = CInt(Int(Rnd() * dpt) + 1) 'choose the random row to swap randcol2 = CInt(Int(Rnd() * dpt) + 1) 'choose the random col to swap
'swap the randomly chosen cells (2 of them) Dim tempdst As Double tempdst = dst_matrix(randrow1, randcol1) ' take the first randomly chosen location cell dst_matrix(randrow1, randcol1) = dst_matrix(randrow2, randcol2) 'assign the dst to the cell dst_matrix(randrow2, randcol2) = tempdst ' complete swap
'do same for material flow matrix from the same positions randomly chosen in the randomly chosen time period 'swap the randomly chosen cells (2 of them) Dim tempmat As Double fac = (randtp - 1) * dpt
tempmat = dst_matrix(randrow1 + fac, randcol1) ' take the first randomly chosen location cell mat_matrix(randrow1 + fac, randcol1) = mat_matrix(randrow2 + fac, randcol2) 'assign the dst to the cell mat_matrix(randrow2 + fac, randcol2) = tempmat ' complete swap
If TC < initTC Then initTC = TC 'update the new Total Cost on the New Dynamic Layout for each iteration Frmsum.Text3 = initTC End If
Next
End Sub
Private Sub material_Click() frmmat.Show End Sub Private Sub distance_Click() frmdst.Show End Sub
Private Sub new_Click() Dim theans As Variant theans = MsgBox("This will wipe out old ant data!", vbOKCancel, "New") If theans = vbOK Then Unload Form2 Unload form3 Unload form4 Unload frmcloseness Unload frmdst Unload Frmsum Unload Me Me.Show Reset Command1.Visible = True
Private Sub trail_Click() On Error Resume Next Pt = 1 / ((10 ^ -8) * initTC) ' initTC holds the current best total cost found while Q is translated 10 -8 Frmsum.Text4 = FormatNumber(Pt, 2) Frmsum.Show Me.viewpherome.Enabled = True End Sub
'enter the values from the flexgrid into array Dim fac As Integer d_start = (current_tp * dpt) + 1 - dpt d_end = current_tp * dpt fac = (current_tp - 1) * dpt 'save table to temp array For i = d_start To d_end For j = 1 To dpt 'MsgBox ("mat_matrix(" & i & " , " & j & ") = " & material.TextMatrix(i - fac, j)) mat_matrix(i, j) = material.TextMatrix(i - fac, j) Next Next
MsgBox ("Time Periods completed") cmd_next_matrix.Visible = True Command1.Visible = False Command2.Visible = True Exit Sub End If 'reset grid for new entry
Call initialize
End Sub
Private Sub Form_Load() 'work on the first time period current_tp = 1 banner_label = banner_label.Caption & " " & current_tp
Call initialize
End Sub Public Sub initialize() Dim i, j As Integer 'setting the total number of rows and columns material.Rows = dpt + 1 material.Cols = dpt + 1
Next
For i = 1 To dpt For j = 1 To dpt If i = j Then material.TextMatrix(i, j) = 0 End If Next Next End Sub
Public Sub material_Click() i = material.Row j = material.Col Dim user_entry As Variant user_entry = InputBox("Enter Value", "Data", material.TextMatrix(i, j))
End Sub
Private Sub material_KeyPress(KeyAscii As Integer) i = material.Row j = material.Col 'If material.TextMatrix(i, j) = "" Then 'material.TextMatrix(i, j) = CInt(KeyAscii) 'End If Call material_Click End Sub
'enter the values from the flexgrid into array Dim fac As Integer d_start = (current_tp * dpt) + 1 - dpt d_end = current_tp * dpt fac = (current_tp - 1) * dpt 'save table to temp array For i = d_start To d_end For j = 1 To dpt dst_matrix(i, j) = distance.TextMatrix(i - fac, j) Next Next
cmd_next_matrix.Visible = True
Command2.Visible = True
Public Sub initialize() Dim i, j As Integer 'setting the total number of rows and columns distance.Rows = dpt + 1 distance.Cols = dpt + 1
DC = 0 'initialize DC
N = dpt T = tp For i = 1 To N - 1 For j = i + 1 To N For tt = 1 To T 'tt is t because of variable issue fac = (tt - 1) * dpt
it = i + fac ' it takes into consideration the time period of the material flow 'MsgBox ("current i:" & it) 'formular goes here
End Sub Public Sub Command4_Click() Dim N, T, it As Integer Dim Rijpq As Double
AC = 0 'initialize DC
'formular goes here 'if p and q are neighbors 'ie adjacency Dim first, second, val As Integer first = i + j second = p + q val = Abs(second - first)
AC = AC + (Rijpq * 1 * 1)
Frmsum.Text2 = FormatNumber(AC, 2)
Frmsum.Show
End Sub
TC = W2 * DC - W1 * AC Frmsum.Text3 = FormatNumber(TC, 2) Form1.summary.Visible = True Form1.summary.Visible = True Frmsum.Show Form1.Show End Sub
Public Sub distance_Click() i = distance.Row j = distance.Col Dim user_entry As Variant user_entry = InputBox("Enter Value", "Data", distance.TextMatrix(i, j))
distance.TextMatrix(i, j) = user_entry distance.TextMatrix(j, i) = user_entry Call initialize ' calling to check for the constant zeros
End Sub
End Sub
Form1.distance.Enabled = True
End Sub
'enter the values from the flexgrid into array Dim fac As Integer d_start = (current_tp * dpt) + 1 - dpt d_end = current_tp * dpt fac = (current_tp - 1) * dpt 'save table to temp array For i = d_start To d_end For j = 1 To dpt 'MsgBox ("C(" & i & " , " & j & ") = " & closeness.TextMatrix(i - fac, j))
Dim tempC As Integer tempC = 0 'if no one is selected If closeness.TextMatrix(i - fac, j) = "A" Or closeness.TextMatrix(i - fac, j) = "a" Then tempC = 4 End If
If closeness.TextMatrix(i - fac, j) = "E" Or closeness.TextMatrix(i - fac, j) = "e" Then tempC = 3 End If If closeness.TextMatrix(i - fac, j) = "I" Or closeness.TextMatrix(i - fac, j) = "i" Then tempC = 2 End If If closeness.TextMatrix(i - fac, j) = "O" Or closeness.TextMatrix(i - fac, j) = "o" Then tempC = 1 End If If closeness.TextMatrix(i - fac, j) = "U" Or closeness.TextMatrix(i - fac, j) = "u" Then tempC = 0 End If If closeness.TextMatrix(i - fac, j) = "X" Or closeness.TextMatrix(i - fac, j) = "x" Then tempC = -1 End If
Next Next
form3.Command5.Visible = True form3.Command3.Visible = True form3.Command4.Visible = True form3.Show Exit Sub End If 'reset grid for new entry
closeness.Clear
current_tp = current_tp + 1
Call initialize
End Sub
End Sub
Private Sub Form_Load() 'work on the first time period current_tp = 1 banner_label = banner_label.Caption & " " & current_tp Call initialize
Form1.closeness.Enabled = True
End Sub Public Sub initialize() Dim i, j As Integer 'setting the total number of rows and columns closeness.Rows = dpt + 1 closeness.Cols = dpt + 1
closeness.TextMatrix(0, 0) = "From/To" For i = 1 To dpt 'numbering the headings closeness.TextMatrix(0, i) = "D" & i closeness.TextMatrix(i, 0) = "D" & i
For i = 1 To dpt For j = 1 To dpt If i = j Then closeness.TextMatrix(i, j) = "-" End If Next Next End Sub
Public Sub closeness_Click() i = closeness.Row j = closeness.Col Dim user_entry As Variant user_entry = InputBox("Enter Value", "Data", closeness.TextMatrix(i, j))
closeness.TextMatrix(i, j) = user_entry closeness.TextMatrix(j, i) = user_entry Call initialize ' calling to check for the constant zeros
End Sub
Private Sub Form_Load() 'setting the total number of rows and columns closesummary.Rows = dpt * tp + 1 closesummary.Cols = dpt + 1
Dim fac As Integer For current_tp = 1 To tp 'MsgBox ("dpt:" & dpt) 'MsgBox ("tp:" & tp) d_start = (current_tp * dpt) + 1 - dpt d_end = tp * dpt fac = (current_tp - 1) * dpt
closesummary.ColWidth(j) = 700 closesummary.TextMatrix(i, 0) = "Period(s) " closesummary.TextMatrix(0, j) = "Dept " & j 'MsgBox ("mat_matrix(" & i & ", " & j & ")" & mat_matrix(i, j)) 'MsgBox ("fac:" & fac) closesummary.TextMatrix(i, j) = C(i, j) Next
Next Next
End Sub
Private Sub Form_Load() 'setting the total number of rows and columns dstsummary.Rows = dpt + 1 dstsummary.Cols = dpt + 1
'Dim fac As Integer 'For current_tp = 1 To tp 'MsgBox ("dpt:" & dpt) 'MsgBox ("tp:" & tp) 'd_start = (current_tp * dpt) + 1 - dpt d_end = dpt 'fac = (current_tp - 1) * dpt 'MsgBox (d_start) 'MsgBox ("fac" & fac)
For j = 1 To dpt For i = 1 To d_end 'NO OF PERIODS TIMES THE DPT NO dstsummary.ColWidth(j) = 700 dstsummary.TextMatrix(0, j) = "Dept " & j 'MsgBox ("dst_matrix(" & i & ", " & j & ")" & dst_matrix(i, j)) 'MsgBox ("fac:" & fac) dstsummary.TextMatrix(i, j) = dst_matrix(i, j) Next Next
End Sub
Private Sub Form_Load() 'setting the total number of rows and columns matsummary.Rows = dpt * tp + 1 matsummary.Cols = dpt + 1
Dim fac As Integer For current_tp = 1 To tp 'MsgBox ("dpt:" & dpt) 'MsgBox ("tp:" & tp) d_start = (current_tp * dpt) + 1 - dpt d_end = tp * dpt fac = (current_tp - 1) * dpt
matsummary.ColWidth(j) = 700 matsummary.TextMatrix(i, 0) = "Period(s) " matsummary.TextMatrix(0, j) = "Dept " & j 'MsgBox ("mat_matrix(" & i & ", " & j & ")" & mat_matrix(i, j)) 'MsgBox ("fac:" & fac) matsummary.TextMatrix(i, j) = mat_matrix(i, j) Next
Next Next
End Sub
End Sub
Private Sub Form_Load() Dim i, j As Integer 'setting the total number of rows and columns data.Rows = dpt + 1 data.Cols = dpt + 1
data.TextMatrix(i, j) = Pt
Next Next
data.TextMatrix(i, j) = (1 - a1) * Pt
Next Next