Вы находитесь на странице: 1из 33

Global dpt, tp, current_tp, R As Integer Global mat_matrix(1000, 1000) As Variant Global dst_matrix(1000, 1000) As Variant Global adj_matrix(1000,

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)

improve.Enabled = True Form2.Show

Command1.Visible = False

End Sub

Private Sub exit_Click() End End Sub Private Sub closeness_Click() frmcloseness.Show End Sub

Private Sub Form_Load()

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

Frmsum.Text6 = initAC Frmsum.Text5 = initDC Frmsum.Text7 = initTC

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

'then compute DC , AC then TC Call form3.Command3_Click Call form3.Command4_Click Call form3.Command5_Click

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

End If End Sub

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

Private Sub viewpherome_Click() pheromesummary.Show End Sub

Private Sub cmd_next_matrix_Click() form3.Show End Sub

Private Sub Command1_Click()

'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 Period Data Saved!")

'check if max time period reached If current_tp = tp Then

MsgBox ("Time Periods completed") cmd_next_matrix.Visible = True Command1.Visible = False Command2.Visible = True Exit Sub End If 'reset grid for new entry

material.Clear current_tp = current_tp + 1

banner_label = "TIME PERIOD" & " " & current_tp

Call initialize

End Sub

Private Sub Command2_Click() frmmat.Show End Sub

Private Sub Form_Load() 'work on the first time period current_tp = 1 banner_label = banner_label.Caption & " " & current_tp

Call initialize

'enable the menu item Form1.material.Enabled = True

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

material.TextMatrix(0, 0) = "From/To" For i = 1 To dpt 'numbering the headings material.TextMatrix(0, i) = i material.TextMatrix(i, 0) = i

'setting width of each column material.ColWidth(i) = 350 material.ColWidth(0) = 700

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

Private Sub Form_Unload(Cancel As Integer) Me.Hide 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))

material.TextMatrix(i, j) = user_entry 'setting the alternate values material.TextMatrix(j, i) = user_entry

Call initialize ' calling to check for the constant zeros

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

Private Sub cmd_next_matrix_Click() form4.Show End Sub

Private Sub Command1_Click()

'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

MsgBox ("Distance Matrix Data Saved!")

cmd_next_matrix.Visible = True

Command2.Visible = True

'reset grid for new entry End Sub

Public Sub initialize() Dim i, j As Integer 'setting the total number of rows and columns distance.Rows = dpt + 1 distance.Cols = dpt + 1

distance.TextMatrix(0, 0) = "From/To" For i = 1 To dpt 'numbering the headings distance.TextMatrix(0, i) = i distance.TextMatrix(i, 0) = i

'setting width of each column distance.ColWidth(i) = 350 distance.ColWidth(0) = 700 Next

For i = 1 To dpt For j = 1 To dpt

If i = j Then distance.TextMatrix(i, j) = 0 End If Next Next End Sub

Private Sub Command2_Click() frmdst.Show End Sub

Public Sub Command3_Click() Dim N, T, it As Integer

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

DC = DC + (dst_matrix(i, j) * mat_matrix(it, j))

Next Next Next

DC = DC + rc 'adding the Retribution cost to get final DC

Frmsum.Text1 = FormatNumber(DC, 2) Frmsum.Show

End Sub Public Sub Command4_Click() Dim N, T, it As Integer Dim Rijpq As Double

AC = 0 'initialize DC

N = dpt 'T = tp For i = 1 To N For j = 1 To N For p = 1 To N For q = 1 To N

'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)

If val = 1 Then Rijpq = CDbl(C(p, q)) Else Rijpq = 0 End If

AC = AC + (Rijpq * 1 * 1)

Next Next Next Next

Frmsum.Text2 = FormatNumber(AC, 2)

Frmsum.Show

End Sub

Public Sub Command5_Click() 'TC =W2DC -W1AC

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

Private Sub distance_KeyPress(KeyAscii As Integer) Call distance_Click

End Sub

Private Sub Form_Load() current_tp = 1 Call initialize

Form1.distance.Enabled = True

End Sub

Private Sub cmd_next_matrix_Click() form3.Show End Sub

Private Sub Command1_Click()

'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))

'translate the A E O I U to numbers

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

'put resolved value in the matrix C(i, j) = tempC

Next Next

MsgBox ("Time Period Data Saved!")

'check if max time period reached

If current_tp = tp Then MsgBox ("Time Periods completed")

Command2.Visible = True Command1.Visible = False

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

banner_label = "TIME PERIOD" & " " & current_tp

Call initialize

End Sub

Private Sub Command2_Click() frmcloseness.Show

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

'setting width of each column closeness.ColWidth(i) = 700

closeness.ColWidth(0) = 700 Next

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 closeness_KeyPress(KeyAscii As Integer)

Call closeness_Click 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

'MsgBox ("fac" & fac)

For i = 1 To d_end 'NO OF PERIODS TIMES THE DPT NO For j = 1 To 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

'MsgBox ("fac" & fac)

For i = 1 To d_end 'NO OF PERIODS TIMES THE DPT NO For j = 1 To 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

Private Sub Command1_Click() Me.PrintForm End Sub

Private Sub Form_Load() Form1.summary.Enabled = True

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(0, 0) = "" For i = 1 To dpt 'numbering the headings data.TextMatrix(0, i) = i data.TextMatrix(i, 0) = i

'setting width of each column data.ColWidth(i) = 350 data.ColWidth(0) = 700 Next

For i = 1 To dpt For j = 1 To dpt

data.TextMatrix(i, j) = Pt

Next Next

'weaken the pherome trail matrix Pp(i)j = (1-a1)* Pp(i)j

For i = 1 To dpt For j = 1 To dpt

data.TextMatrix(i, j) = (1 - a1) * Pt

Next Next

' Pp*(i)i = Pp*(i)i + a2/f(p*)

For i = 1 To dpt For j = 1 To dpt

data.TextMatrix(i, j) = CDbl(data.TextMatrix(i, j)) + a2 / initTC

Next Next End Sub

Вам также может понравиться