0% found this document useful (0 votes)
26 views33 pages

Instructions

The document describes an Excel application that implements the Analytic Hierarchy Process (AHP) for multi-criteria decision making. It includes Visual Basic code to input criteria and alternatives, build pairwise comparison matrices, calculate weights, and check consistency. The application helps users evaluate alternatives and outputs the best option.

Uploaded by

Như Vũ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views33 pages

Instructions

The document describes an Excel application that implements the Analytic Hierarchy Process (AHP) for multi-criteria decision making. It includes Visual Basic code to input criteria and alternatives, build pairwise comparison matrices, calculate weights, and check consistency. The application helps users evaluate alternatives and outputs the best option.

Uploaded by

Như Vũ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

HO CHI MINH UNIVERSITY OF TECHNOLOGY OFFICE FOR

INTERNATIONAL STUDY PROGRAMS

PROJECT REPORT
COMPUTER APPLICATIONS

CC01 - GROUP 06 - SEMESTER 221

Submission Date: 07/01/2023

Instructors: Hồ Thanh Phong


Student: Vũ Nguyên Quỳnh Như 2053309
Trần Minh Phương 2152254
Phạm Thị Thu Thảo 2153809
Đoàn Thị Thanh Xuân 2153996
Ho Chi Minh City – January, 2023

HO CHI MINH UNIVERSITY OF TECHNOLOGY OFFICE FOR


INTERNATIONAL STUDY PROGRAMS

PROJECT REPORT
COMPUTER APPLICATIONS

CC01 - GROUP 06 - SEMESTER 221

Submission Date: 07/01/2023

Instructors: Hồ Thanh Phong


Student: Vũ Nguyên Quỳnh Như 2053309
Trần Minh Phương 2152254
Phạm Thị Thu Thảo 2153809
Đoàn Thị Thanh Xuân 2153996
Ho Chi Minh City – January, 2023

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

n = InputBox("So tieu chi dung de danh gia ")


c = InputBox("So lua chon: ")
o = Sheets.Count

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

k = MsgBox("Nhap Pairwise cho cac tieu chi", vbOKOnly)

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

Sheets("Criteria").Cells(2 * n + 6, 1) = "Lamda Max"


Sheets("Criteria").Cells(2 * n + 6, 2) = s / 3
Sheets("Criteria").Cells(2 * n + 7, 1) = "CI"
Sheets("Criteria").Cells(2 * n + 7, 2) = (Sheets("Criteria").Cells(2 * n + 6, 2) -
n) / (n - 1)

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

Sheets(a).Cells(2 * c + 6, 1) = "Lamda Max"


Sheets(a).Cells(2 * c + 6, 2) = s / 3
Sheets(a).Cells(2 * c + 7, 1) = "CI"
Sheets(a).Cells(2 * c + 7, 2) = (Sheets(a).Cells(2 * c + 6, 2) - c) / (c - 1)

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.

The way we create this software:

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.

We use the function for importing the data:

object_list = @OLE([‘spreadsheet_file’] [, range_name_list]);

We use the function for exporting the solutions:


@OLE( ['spreadsheet_file’] [, range_name_list]) = object_list;

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.1 LINGO Code:

2.1.2 VBA-Sheet:
2.1.3 Create a button to input data:

2.1.4 Create a button for solving:


2.1.4 Instruction:

Example problem: A company sells 3 types of products: Product 1, Product 2,


Product 3. Each product contains a specified ratio of frame wood and glass. The
table below shows information about the unit profit of each product, the supply of
frame wood and glass and the number of materials contained in each product.
Determine the number of each product to produce each day to maximize total
revenue without exceeding the available supply of materials.

Material 1 2 3 Supply

1 3 4 2 30

2 4 6 2 40

Unit profit 5 7 3 Thousands of dollars

Firstly, input the number of products and the number of materials and their
names:
Secondly, input the data into the table

Then, click the solve button

Finally, the problem is solved


2.2 TRANSPORTATION

2.2.1 LINGO Code

2.2.2 VBA-Sheet:
2.2.3 Create a button to input data

2.2.4 Create a button for solving

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

Xuong1 550 300 400 40

Xuong2 350 300 100 20

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

Then, click the solve button

Finally, the problem is solved

2.3 LOGISTICS (LOCATION PROBLEM)

2.3.1 LINGO Code


2.3.2 VBA-Sheet

2.3.3 Create a button to input data


2.3.4 Create a button for solving

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

Demand 80 270 250 160 180

Facility Activation Cost Maximum amount

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

Then, click the solve button

Finally, the problem is solved


2.4 SCHEDULING

2.4.1 LINGO Code


2.4.2 VBA-Sheet

2.4.3 Create a button to input data


2.4.4 Create a button for solving

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.

DAY MON TUE WED THU FR SAT SUN


I

STAFF REQUIRED 16 25 10 23 17 12 14

Firstly, click the “INPUT” button to ipnut data

Secondly, input data into the table


Then, click the solve button

Finally, the problem is solved

2.5 KNAPSACK

2.5.1 LINGO Code

2.5.2 VBA-Sheet
2.5.3 Create a button to input data

2.5.4 Create a button for solving

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

Firstly, input the number of items and their names

Secondly, input the data into the table


Then, click the solve button

Finally, the problem is solved

You might also like