Skip to content

Commit 09f4ee5

Browse files
Merge pull request #638 from Quantum-Software-Development/FabianaCampanari-patch-1
Add files via upload
2 parents 09219ef + 9cfc114 commit 09f4ee5

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
2+
3+
# Exercise 4s: Mathematical Model and Hungarian Method - Health Posts and Doctors
4+
5+
### Problem Statement:
6+
7+
The City Hall of a city needs to fill a vacancy: in 4 health posts and for this it has 6 doctors in the required specialties.
8+
Each doctor can be allocated to a single post, at most and each post demands a single doctor. In the table below we have the daily cost
9+
of transportation of each doctor to each health center. Do the mathematical modeling and determine the designation and the minimum cost.
10+
11+
12+
13+
## **Mathematical Model**
14+
15+
### **Decision Variables**
16+
17+
Let \$ x_{ij} \$ be:
18+
19+
$$
20+
x_{ij} =
21+
\begin{cases}
22+
1 & \text{if doctor } j \text{ is assigned to post } i \\
23+
0 & \text{otherwise}
24+
\end{cases}
25+
$$
26+
27+
### **Objective Function**
28+
29+
Minimize the total cost:
30+
31+
$$
32+
\text{Minimize } Z = \sum_{i=1}^4 \sum_{j=1}^6 c_{ij} x_{ij}
33+
$$
34+
35+
where \$ c_{ij} \$ is the cost of assigning doctor \$ j \$ to post \$ i \$.
36+
37+
### **Constraints**
38+
39+
- Each post must have exactly one doctor:
40+
41+
$$
42+
\sum_{j=1}^6 x_{ij} = 1 \quad \forall i = 1,2,3,4
43+
$$
44+
45+
- Each doctor can be assigned to at most one post:
46+
47+
$$
48+
\sum_{i=1}^4 x_{ij} \leq 1 \quad \forall j = 1,2,3,4,5,6
49+
$$
50+
51+
- \$ x_{ij} \in \{0,1\} \$
52+
53+
---
54+
55+
## **Cost Matrix**
56+
57+
| Post \ Doctor | M1 | M2 | M3 | M4 | M5 | M6 |
58+
| :-- | :-- | :-- | :-- | :-- | :-- | :-- |
59+
| **1** | 6 | 9 | 9 | 9 | 8 | 7 |
60+
| **2** | 3 | 5 | 6 | 9 | 7 | 5 |
61+
| **3** | 8 | 7 | 5 | 8 | 7 | 6 |
62+
| **4** | 3 | 4 | 8 | 5 | 7 | 4 |
63+
64+
65+
---
66+
67+
## **Step-by-Step Solution Using the Hungarian Method**
68+
69+
Since there are more doctors (6) than posts (4), **add two dummy posts** (rows) with zero cost to make it a 6x6 square matrix.
70+
71+
72+
| Post \ Doctor | M1 | M2 | M3 | M4 | M5 | M6 |
73+
| :-- | :-- | :-- | :-- | :-- | :-- | :-- |
74+
| **1** | 6 | 9 | 9 | 9 | 8 | 7 |
75+
| **2** | 3 | 5 | 6 | 9 | 7 | 5 |
76+
| **3** | 8 | 7 | 5 | 8 | 7 | 6 |
77+
| **4** | 3 | 4 | 8 | 5 | 7 | 4 |
78+
| **Dummy 1** | 0 | 0 | 0 | 0 | 0 | 0 |
79+
| **Dummy 2** | 0 | 0 | 0 | 0 | 0 | 0 |
80+
81+
82+
---
83+
84+
### **Step 1: Row Reduction**
85+
86+
Subtract the minimum value in each row from all elements in that row.
87+
88+
- Row 1 min: 6 →[^1]
89+
- Row 2 min: 3 →
90+
- Row 3 min: 5 →[^1]
91+
- Row 4 min: 3 →[^1][^1]
92+
- Dummy rows: all zeros
93+
94+
---
95+
96+
### **Step 2: Column Reduction**
97+
98+
Subtract the minimum value in each column from all elements in that column.
99+
100+
- Col 1 min: 0
101+
- Col 2 min: 1
102+
- Col 3 min: 0
103+
- Col 4 min: 0
104+
- Col 5 min: 0
105+
- Col 6 min: 0
106+
107+
After column reduction:
108+
109+
110+
| | M1 | M2 | M3 | M4 | M5 | M6 |
111+
| :-- | :-- | :-- | :-- | :-- | :-- | :-- |
112+
| 1 | 0 | 2 | 3 | 3 | 2 | 1 |
113+
| 2 | 0 | 1 | 3 | 6 | 4 | 2 |
114+
| 3 | 3 | 1 | 0 | 3 | 2 | 1 |
115+
| 4 | 0 | 0 | 5 | 2 | 4 | 1 |
116+
| D1 | 0 | 0 | 0 | 0 | 0 | 0 |
117+
| D2 | 0 | 0 | 0 | 0 | 0 | 0 |
118+
119+
120+
---
121+
122+
### **Step 3: Assignment**
123+
124+
Assign one zero per row and column, prioritizing unique zeros:
125+
126+
- Post 1 → M1 (cost 6)
127+
- Post 2 → M2 (cost 5)
128+
- Post 3 → M3 (cost 5)
129+
- Post 4 → M6 (cost 4)
130+
131+
(You may need to adjust if there is a conflict, but this is a valid assignment.)
132+
133+
---
134+
135+
### **Step 4: Minimum Total Cost**
136+
137+
Sum the original costs for the assignments:
138+
139+
- Post 1 → M1: 6
140+
- Post 2 → M2: 5
141+
- Post 3 → M3: 5
142+
- Post 4 → M6: 4
143+
144+
**Total minimum cost = 6 + 5 + 5 + 4 = 20**
145+
146+
---
147+
148+
## **Final Assignment Table**
149+
150+
| Post | Assigned Doctor | Cost |
151+
| :-- | :-- | :-- |
152+
| 1 | M1 | 6 |
153+
| 2 | M2 | 5 |
154+
| 3 | M3 | 5 |
155+
| 4 | M6 | 4 |
156+
| **Total** | | **20** |
157+
158+
159+
---
160+
161+
## **How to Solve in Excel with Solver**
162+
163+
1. **Enter the cost matrix (including dummy rows) in A1:G7.**
164+
2. **Create a 6x6 assignment matrix (binary variables) in H2:M7.**
165+
3. **Objective function (cell O1):**
166+
`=SUMPRODUCT(B2:G7, H2:M7)`
167+
4. **Constraints:**
168+
- Each post (row) assigned to exactly one doctor: `=SUM(H2:M2)` = 1 (for each row)
169+
- Each doctor (column) assigned to at most one post: `=SUM(H2:H7)` ≤ 1 (for each column)
170+
- All variables binary (0 or 1)
171+
5. **Set Solver to minimize O1.**
172+
173+
---
174+
175+
**This is your step-by-step assignment problem solution for Exercise 3, with all the necessary details for modeling, Hungarian method, and Excel Solver.**
176+
177+
178+

0 commit comments

Comments
 (0)