Question: The code below gives me a type miss match. I think its returning 0 for the pivot row calculations. Sub SimplexMethod ( ) Dim tableau
The code below gives me a type miss match. I think its returning for the pivot row calculations.
Sub SimplexMethod
Dim tableau As Range
Dim numRows As Integer, numCols As Integer
Dim pivotRow As Integer, pivotCol As Integer
Dim i As Integer, j As Integer
Dim minRatio As Double, ratio As Double
Define the range of the initial tableau
Set tableau ThisWorkbook.SheetsTableauRangeA:E
numRows tableau.Rows.Count
numCols tableau.Columns.Count
Do
Step : Identify the pivot column most negative value in the objective row
pivotCol
For j To numCols
If tableau.CellsnumRows jValue tableau.CellsnumRows pivotColValue Then
pivotCol j
End If
Next j
If all values in the objective row are nonnegative, the solution is optimal
If tableau.CellsnumRows pivotColValue Then Exit Do
Step : Identify the pivot row minimum positive ratio of RHS to pivot column
minRatio E
For i To numRows
If tableau.Cellsi pivotColValue Then
ratio tableau.Cellsi numColsValue tableau.Cellsi pivotColValue
If ratio minRatio Then
minRatio ratio
pivotRow i
End If
End If
Next i
Step : Perform pivot operation
Pivot tableau, pivotRow, pivotCol
Loop
Output the optimal solution
MsgBox "Optimal solution found. Objective value: & tableau.CellsnumRows numColsValue
End Sub
Sub Pivottableau As Range, pivotRow As Integer, pivotCol As Integer
Dim numRows As Integer, numCols As Integer
Dim i As Integer, j As Integer
Dim pivotValue As Double
numRows tableau.Rows.Count
numCols tableau.Columns.Count
pivotValue tableau.CellspivotRow pivotColValue
Divide the pivot row by the pivot element
For j To numCols
tableau.CellspivotRow jValue tableau.CellspivotRow jValue pivotValue
Next j
Subtract multiples of the pivot row from the other rows
For i To numRows
If i pivotRow Then
pivotValue tableau.Cellsi pivotColValue
For j To numCols
tableau.Cellsi jValue tableau.Cellsi jValue pivotValue tableau.CellspivotRow jValue
Next j
End If
Next i
End Sub
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
