Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sub SolveAssemblyLineBalancing ( ) ' Define the task times and precedence constraints Dim taskTimes ( ) As Integer taskTimes = Array ( 3 , 2

Sub SolveAssemblyLineBalancing()
' Define the task times and precedence constraints
Dim taskTimes() As Integer
taskTimes = Array(3,2,4,5,6,2,3,4,3,2,5)' Example task times
Dim predecessors(10) As Collection
Set predecessors(0)= New Collection ' Task 1
predecessors(0).Add 0' No predecessors
Set predecessors(1)= New Collection ' Task 2
predecessors(1).Add 1' Task 1 is a predecessor
Set predecessors(2)= New Collection ' Task 3
predecessors(2).Add 1
Set predecessors(3)= New Collection ' Task 4
predecessors(3).Add 2' Task 2 is a predecessor
Set predecessors(4)= New Collection ' Task 5
predecessors(4).Add 3' Task 3 is a predecessor
Set predecessors(5)= New Collection ' Task 6
predecessors(5).Add 4' Task 4 is a predecessor
Set predecessors(6)= New Collection ' Task 7
predecessors(6).Add 4
Set predecessors(7)= New Collection ' Task 8
predecessors(7).Add 5
Set predecessors(8)= New Collection ' Task 9
predecessors(8).Add 6
Set predecessors(9)= New Collection ' Task 10
predecessors(9).Add 7
Set predecessors(10)= New Collection ' Task 11
predecessors(10).Add 8
' Define the cycle time and maximum number of workstations
Dim cycleTime As Integer
cycleTime =10
Dim maxStations As Integer
maxStations =2
Dim maxWorkersPerStation As Integer
maxWorkersPerStation =3
' Step 1: Compute the positional weights
Dim positionalWeights() As Integer
ReDim positionalWeights(UBound(taskTimes))
Dim i As Integer, j As Integer
For i = UBound(taskTimes) To LBound(taskTimes) Step -1
positionalWeights(i)= taskTimes(i)
For Each pred In predecessors(i)
positionalWeights(i)= positionalWeights(i)+ positionalWeights(pred -1)
Next pred
Next i
' Step 2: Sort tasks by positional weights in descending order
Dim sortedTasks() As Integer
sortedTasks = SortTasksByPositionalWeight(positionalWeights)
' Step 3: Assign tasks to workstations
Dim stationLoad(maxStations) As Integer
Dim stationTasks(maxStations) As Collection
For i =0 To maxStations -1
Set stationTasks(i)= New Collection
Next i
Dim taskAssigned() As Boolean
ReDim taskAssigned(UBound(taskTimes))
For Each task In sortedTasks
For i =0 To maxStations -1
If stationLoad(i)+ taskTimes(task)= cycleTime And stationTasks(i).Count maxWorkersPerStation Then
stationTasks(i).Add task +1
stationLoad(i)= stationLoad(i)+ taskTimes(task)
taskAssigned(task)= True
Exit For
End If
Next i
Next task
' Output the assignment of tasks to workstations
For i =0 To maxStations -1
Debug.Print "Station " & i +1 & ":"
For Each task In stationTasks(i)
Debug.Print " Task " & task
Next task
Next i
End Sub
Function SortTasksByPositionalWeight(weights() As Integer) As Integer()
Dim indices() As Integer
Dim i As Integer, j As Integer, temp As Integer
ReDim indices(UBound(weights))
For i = LBound(weights) To UBound(weights)
indices(i)= i
Next i
For i = LBound(weights) To UBound(weights)-1
For j = i +1 To UBound(weights)
If weights(indices(j))> weights(indices(i)) Then
temp = indices(i)
indices(i)= indices(j)
indices(j)= temp
End If
Next j
Next i
SortTasksByPositionalWeight = indices
End Function
.
I'm getting an error in the VBA code I wrote to solve this problem. Can you help me?
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

Describe the characteristics of a 360-degree performance appraisal.

Answered: 1 week ago