Instructions
Instructions
PROJECT REPORT
COMPUTER APPLICATIONS
PROJECT REPORT
COMPUTER APPLICATIONS
TABLE OF CONTENTS
1. AHP______________________________________________________________________4
1.1 Instructions_______________________________________________________________4
1.2 AHP Code_________________________________________________________________6
2. LINEAR PROGRAMING___________________________________________________15
2.1 PRODUCTION___________________________________________________________16
2.1.1 LINGO Code:__________________________________________________________16
2.1.2 VBA-Sheet:___________________________________________________________16
2.1.3 Create a button to input data:______________________________________________17
2.1.4 Create a button for solving:_______________________________________________17
2.1.4 Instruction:____________________________________________________________18
2.2 TRANSPORTATION______________________________________________________20
2.2.1 LINGO Code__________________________________________________________20
2.2.2 VBA-Sheet:___________________________________________________________20
2.2.3 Create a button to input data______________________________________________21
2.2.4 Create a button for solving________________________________________________21
2.2.5 Instruction____________________________________________________________21
2.3 LOGISTICS (LOCATION PROBLEM)______________________________________23
2.3.1 LINGO Code__________________________________________________________23
2.3.2 VBA-Sheet____________________________________________________________24
2.3.3 Create a button to input data______________________________________________24
2.3.4 Create a button for solving________________________________________________25
2.3.5 Instruction____________________________________________________________25
2.4 SCHEDULING___________________________________________________________27
2.4.1 LINGO Code__________________________________________________________27
2.4.2 VBA-Sheet____________________________________________________________28
2.4.3 Create a button to input data______________________________________________28
2.4.4 Create a button for solving________________________________________________29
2.4.5 Instruction____________________________________________________________29
2.5 KNAPSACK______________________________________________________________30
2.5.1 LINGO Code__________________________________________________________30
2.5.2 VBA-Sheet____________________________________________________________30
2.5.3 Create a button to input data______________________________________________31
2.5.4 Create a button for solving________________________________________________31
2.5.5 Instruction____________________________________________________________31
1. AHP
Note: Please make a name sheet with “Criteria”
1.1 Instructions
Step 1: Input desired amount of Criteria and Alternative. Click “OK” button.
Step 2: Input the name and construct a pairwise comparison matrix for Criteria and
Alternative.
The system automatically solves each Alternative’s point and outputs the best
object
For example:
1.2 AHP Code
Sub AHP()
Dim n As Integer
Dim c As Integer
If o > 1 Then
GoTo Dondulieu
Else: GoTo Luachon
End If
Dondulieu:
If Sheets(1).Name = "Criteria" Then
GoTo Xoasheetthua
Else
Sheets("Criteria").Move Before:=Sheets(1)
GoTo Xoasheetthua
End If
Xoasheetthua:
i=o
For i = 0 To (o - 2)
Application.DisplayAlerts = False
Sheets(o - i).Delete
Application.DisplayAlerts = True
Next i
GoTo Luachon
Luachon:
Sheets("Criteria").Cells.Clear
For i = 1 To n
k = InputBox("Ten tieu chi thu " & i & " la: ")
Sheets("Criteria").Cells(1, i + 1) = k
Sheets("Criteria").Cells(i + 1, 1) = k
Sheets("Criteria").Cells(n + 4, i + 1) = k
Sheets("Criteria").Cells(i + n + 4, 1) = k
Next i
For i = 1 To n
For j = 1 To n
If i = j Then
Sheets("Criteria").Cells(i + 1, j + 1) = 1
ElseIf i < j Then
d = InputBox("Gia tri cua tieu chi " & Sheets("Criteria").Cells(1, i + 1) & "
so voi " & Sheets("Criteria").Cells(j + 1, 1))
Sheets("Criteria").Cells(i + 1, j + 1) = d
Sheets("Criteria").Cells(j + 1, i + 1) = 1 / d
Else
End If
Next j
Next i
For j = 1 To n
s=0
For i = 1 To n
s = s + Sheets("Criteria").Cells(i + 1, j + 1)
Next i
Sheets("Criteria").Cells(n + 2, j + 1) = s
Next j
For i = 1 To n
For j = 1 To n
Sheets("Criteria").Cells(i + n + 4, j + 1) = Sheets("Criteria").Cells(i + 1, j + 1)
/ Sheets("Criteria").Cells(n + 2, j + 1)
Next j
Next i
For i = 1 To n
s=0
For j = 1 To n
s = s + Sheets("Criteria").Cells(i + n + 4, j + 1)
Next j
Sheets("Criteria").Cells(i + n + 4, n + 2) = s / n
Next i
Sheets("Criteria").Range(Cells(n + 5, n + 2), Cells(2 * n + 4, n +
2)).Font.ColorIndex = 3
Sheets("Criteria").Range(Cells(n + 5, n + 2), Cells(2 * n + 4, n + 2)).Font.Bold
= True
LuachonConsistency:
For i = 1 To n
s=0
For j = 1 To n
s = s + Sheets("Criteria").Cells(i + 1, j + 1) * Sheets("Criteria").Cells(j + n
+ 4, n + 2)
Next j
Sheets("Criteria").Cells(i + n + 4, n + 3) = s / Sheets("Criteria").Cells(i + n + 4,
n + 2)
Next i
s=0
For i = 1 To n
s = s + Sheets("Criteria").Cells(i + n + 4, n + 3)
Next i
If n = 3 Then
r = 0.58
ElseIf n = 4 Then
r = 0.9
ElseIf n = 5 Then
r = 1.12
ElseIf n = 6 Then
r = 1.24
ElseIf n = 7 Then
r = 1.32
ElseIf n = 8 Then
r = 1.41
End If
Sheets("Criteria").Cells(2 * n + 8, 2) = Sheets("Criteria").Cells(2 * n + 7, 2) / r
If Sheets("Criteria").Cells(2 * n + 8, 2) > 0.1 Then
Sheets("Criteria").Cells(2 * n + 9, 2) = "No acceptable range for consistency"
Else: Sheets(a).Cells(2 * n + 9, 2) = "Well within the acceptable range for
consistency"""
End If
Tieuchi:
For j = -1 To (n - 2)
Sheets.Add.Name = Sheets("Criteria").Cells(1, n - j)
Next j
For i = 1 To c
k = InputBox("Ten lua chon " & i & " la: ")
For j = 1 To n
h = Sheets("Criteria").Cells(1, j + 1)
Sheets(h).Cells(1, i + 1) = k
Sheets(h).Cells(i + 1, 1) = k
Sheets(h).Cells(c + 4, i + 1) = k
Sheets(h).Cells(i + c + 4, 1) = k
Next j
Next i
For a = 1 To n
Sheets(a).Select
For i = 1 To c
For j = 1 To c
If i = j Then
Sheets(a).Cells(i + 1, j + 1) = 1
ElseIf i < j Then
d = InputBox("Gia tri cua lua chon " & Sheets(a).Cells(1, i + 1) & " so voi
lua chon " & Sheets(a).Cells(j + 1, 1) & " trong tieu chi " & Sheets(a).Name)
Sheets(a).Cells(i + 1, j + 1) = d
Sheets(a).Cells(j + 1, i + 1) = 1 / d
Else
End If
Next j
Next i
For j = 1 To c
s=0
For i = 1 To c
s = s + Sheets(a).Cells(i + 1, j + 1)
Next i
Sheets(a).Cells(c + 2, j + 1) = s
Next j
For i = 1 To c
For j = 1 To c
Sheets(a).Cells(i + c + 4, j + 1) = Sheets(a).Cells(i + 1, j + 1) /
Sheets(a).Cells(c + 2, j + 1)
Next j
Next i
For i = 1 To c
s=0
For j = 1 To c
s = s + Sheets(a).Cells(i + c + 4, j + 1)
Next j
Sheets(a).Cells(i + c + 4, c + 2) = s / c
Next i
Sheets(a).Range(Cells(c + 5, c + 2), Cells(2 * c + 4, c + 2)).Font.ColorIndex = 3
Sheets(a).Range(Cells(c + 5, c + 2), Cells(2 * c + 4, c + 2)).Font.Bold = True
TieuchiConsistency:
For i = 1 To c
s=0
For j = 1 To c
s = s + Sheets(a).Cells(i + 1, j + 1) * Sheets(a).Cells(j + c + 4, c + 2)
Next j
Sheets(a).Cells(i + c + 4, c + 3) = s / Sheets(a).Cells(i + c + 4, c + 2)
Next i
s=0
For i = 1 To c
s = s + Sheets(a).Cells(i + c + 4, c + 3)
Next i
If c = 3 Then
r = 0.58
ElseIf c = 4 Then
r = 0.9
ElseIf c = 5 Then
r = 1.12
ElseIf c = 6 Then
r = 1.24
ElseIf c = 7 Then
r = 1.32
ElseIf c = 8 Then
r = 1.41
End If
Sheets(a).Cells(2 * c + 8, 2) = Sheets(a).Cells(2 * c + 7, 2) / r
If Sheets(a).Cells(2 * c + 8, 2) > 0.1 Then
Sheets(a).Cells(2 * c + 9, 2) = "No acceptable range for consistency"
Else: Sheets(a).Cells(2 * c + 9, 2) = "Well within the acceptable range for
consistency"
End If
Next a
Duaraquyetdinh:
Sheets.Add.Name = ("Ketqua")
Sheets("Ketqua").Select
Sheets("Ketqua").Move After:=Sheets("Criteria")
For i = 1 To n
Sheets("Ketqua").Cells(1, i + 1) = Sheets("Criteria").Cells(1, i + 1)
Sheets("Ketqua").Cells(2, i + 1) = Sheets("Criteria").Cells(i + n + 4, n + 2)
Next i
For i = 1 To c
For j = 1 To n
Sheets("Ketqua").Cells(i + 2, 1) = Sheets(2).Cells(i + 1, 1)
Sheets("Ketqua").Cells(i + 2, j + 1) = Sheets(j).Cells(i + c + 4, c + 2)
Next j
Next i
For i = 1 To c
s=0
For j = 1 To n
s = s + Sheets("Ketqua").Cells(i + 2, j + 1) * Sheets("Ketqua").Cells(2, j + 1)
Next j
Sheets("Ketqua").Cells(i + 2, n + 2) = s
Next i
Max = 0
For i = 1 To c
If Max < Sheets("Ketqua").Cells(i + 2, n + 2) Then
Max = Sheets("Ketqua").Cells(i + 2, n + 2)
x=i+2
End If
Next i
Sheets("Ketqua").Range(Cells(2, n + 2), Cells(c + 2, n + 2)).Font.ColorIndex =
3
Sheets("Ketqua").Range(Cells(2, n + 2), Cells(c + 2, n + 2)).Font.Bold = True
Xuatketqua:
MsgBox ("Gia tri lon nhat la: " & Max & ". Tuong ung voi lua chon " &
Sheets("Ketqua").Cells(x, 1))
Sheets("Ketqua").Cells(c + 4, 2) = "Gia tri lon nhat la: " & Max & ". Tuong ung
voi lua chon " & Sheets("Ketqua").Cells(x, 1)
Sheets("Ketqua").Cells(c + 4, 2).Font.ColorIndex = 3
Sheets("Ketqua").Cells(c + 4, 2).Font.Bold = True
End Sub
2. LINEAR PROGRAMING
In this report, we consider 5 problems:
Production
Transportation
Logistics
Scheduling
Knapsack
For each problem, we create software that allows users to input data entering
through Excel and then automatically call LINGO to solve the linear programming
problem and then return the solution into the Excel file.
1. Firstly, we create an EXCEL file that we define name for the range that we use
data from or define name for the range we want to return the solution into.
2. Secondly, we create a LINGO file (with code suitable for each problem) using
data entered through an Excel file by the user and export the solution to the
Excel File.
3. Then, we create a “VBA” sheet after a sheet including the place we input data
and return the solution. This sheet contains the command script we will use to
solve the model for each problem.
4. Create a button to input data
5. Create a button for solving
6. Finally, problem is solved.
2.1 PRODUCTION
2.1.2 VBA-Sheet:
2.1.3 Create a button to input data:
Material 1 2 3 Supply
1 3 4 2 30
2 4 6 2 40
Firstly, input the number of products and the number of materials and their
names:
Secondly, input the data into the table
2.2.2 VBA-Sheet:
2.2.3 Create a button to input data
2.2.5 Instruction
Example problem: XYZ Inc. operates two plants with weekly production rates of
40 and 20 widgets, respectively. These widgets must be delivered to three
warehouses with orders of 25, 10, and 25 units. The shipping cost between each
site is known (see the grid below). Which manufacturer should make and ship how
many widgets to which warehouses in order to meet demand at each location at the
lowest possible cost?
Cost Kho1 Kho2 Kho3 Supply
Demand 25 10 25
Firstly, input the number of warehouses and the number of factories and their
names:
Secondly, input the data into the table
2.3.5 Instruction
Example problem: Consider a company with three potential sites for installing its
facilities/warehouses and five demand points. Each site has a yearly activation
cost, i.e., an annual leasing expense that is incurred for using it, independently of
the volume it services. This volume is limited to a given maximum amount that
may be handled yearly. Additionally, there is a transportation cost per unit serviced
from facility to the demand point. These data are shown in Table. Minimize the
sum of facility activation costs and transportation costs
Custome 1 2 3 4 5
r
1 4 5 6 8 10 1000 500
2 6 4 3 5 8 1000 500
3 9 7 4 3 4 1000 500
Firstly, input the number of customers and the number of facilities and their
names:
Secondly, input the data into the table
2.4.5 Instruction
Example problem: A salon that is open every day of the week. Employees are
hired by the owner to work a six-day workweek with three consecutive days off.
Each employee is paid the same amount each week. Some days of the week are
busier than others, and the owner knows how many staff are needed on any given
day of the week based on previous experience. These staffing requirements are
specifically mentioned in the prediction. Determine how many employees should
start on each day of the week in order to reduce total employee count while
meeting or exceeding staffing requirements each day of the week.
STAFF REQUIRED 16 25 10 23 17 12 14
2.5 KNAPSACK
2.5.2 VBA-Sheet
2.5.3 Create a button to input data
2.5.5 Instruction
Example problem: Josie Camper is off for a two-day trip. He wants to pack four
goods, but the overall weight cannot exceed 14kg. The weight and utility of each
item are shown in the table below. Determine which items should be included in
Josie's package to meet demand.
Items Weight Utility
1 5 16
2 7 22
3 4 12
4 3 8