Vous êtes sur la page 1sur 10

Vogel's approximation method

TaskVogel's approximation method

You are encouraged to solve this task according to the task description, using any language you may
know.

Vogel's Approximation Method (VAM) is a technique for finding a good initial feasible solution to an
allocation problem.

The powers that be have identified 5 tasks that need to be solved urgently. Being imaginative chaps, they
have called them “A”, “B”, “C”, “D”, and “E”. They estimate that:

A will require 30 hours of work,

B will require 20 hours of work,

C will require 70 hours of work,

D will require 30 hours of work, and

E will require 60 hours of work.

They have identified 4 contractors willing to do the work, called “W”, “X”, “Y”, and “Z”.

W has 50 hours available to commit to working,

X has 60 hours available,

Y has 50 hours available, and

Z has 50 hours available.

The cost per hour for each contractor for each task is summarized by the following table:

A B C D E

W 16 16 13 22 17

X 14 14 13 19 15

Y 19 19 20 23 50
Z 50 12 50 15 11

The task is to use VAM to allocate contractors to tasks. It scales to large problems, so ideally keep sorts
out of the iterative cycle. It works as follows:

Step 1: Balance the given transportation problem if either (total supply>total demand) or (total
supply<total demand)

Step 2: Determine the penalty cost for each row and column by subtracting the lowest cell cost in the
row or column from the next lowest cell cost in the same row or column.

Step 3: Select the row or column with the highest penalty cost (breaking ties arbitrarily or choosing the
lowest-cost cell).

Step 4: Allocate as much as possible to the feasible cell with the lowest transportation cost in the row or
column with the highest penalty cost.

Step 5: Repeat steps 2, 3 and 4 until all requirements have been meet.

Step 6: Compute total transportation cost for the feasible allocations.

For this task assume that the model is balanced.

For each task and contractor (row and column above) calculating the difference between the smallest
two values produces:

A B C D E W X Y Z

1 2 2 0 4 4 3 1 0 1 E-Z(50)

Determine the largest difference (D or E above). In the case of ties I shall choose the one with the lowest
price (in this case E because the lowest price for D is Z=15, whereas for E it is Z=11). For your choice
determine the minimum cost (chosen E above so Z=11 is chosen now). Allocate as much as possible from
Z to E (50 in this case limited by Z's supply). Adjust the supply and demand accordingly. If demand or
supply becomes 0 for a given task or contractor it plays no further part. In this case Z is out of it. If you
choose arbitrarily, and chose D see here for the working.

Repeat until all supply and demand is met:


2 2 2 0 3 2 3 1 0 - C-W(50)

3 5 5 7 4 35 - 1 0 - E-X(10)

4 5 5 7 4 - - 1 0 - C-X(20)

5 5 5 - 4 - - 0 0 - A-X(30)

6 - 19 - 23 - - - 4 - D-Y(30)

- - - - - - - - - B-Y(20)

Finally calculate the cost of your solution. In the example given it is £3100:

A B C D E

W 50

X 30 20 10

Y 20 30

Z 50

The optimal solution determined by GLPK is £3100:

A B C D E

W 50

X 10 20 20 10

Y 20 30

Z 50

Cf.

Transportation problem

Contents [hide]

1C
2D

3 Go

4J

5 Java

6 Julia

7 Kotlin

8 Perl 6

9 Phix

10 Python

11 Racket

12 Ruby

12.1 Task Example

12.2 Reference Example

13 Sidef

14 Tcl

15 Yabasic

16 zkl

C[edit]

Translation of: Kotlin

#include <stdio.h>

#include <limits.h>

#define TRUE 1

#define FALSE 0

#define N_ROWS 4
#define N_COLS 5

typedef int bool;

int supply[N_ROWS] = { 50, 60, 50, 50 };

int demand[N_COLS] = { 30, 20, 70, 30, 60 };

int costs[N_ROWS][N_COLS] = {

{ 16, 16, 13, 22, 17 },

{ 14, 14, 13, 19, 15 },

{ 19, 19, 20, 23, 50 },

{ 50, 12, 50, 15, 11 }

};

bool row_done[N_ROWS] = { FALSE };

bool col_done[N_COLS] = { FALSE };

void diff(int j, int len, bool is_row, int res[3]) {

int i, c, min1 = INT_MAX, min2 = min1, min_p = -1;

for (i = 0; i < len; ++i) {

if((is_row) ? col_done[i] : row_done[i]) continue;

c = (is_row) ? costs[j][i] : costs[i][j];

if (c < min1) {

min2 = min1;

min1 = c;
min_p = i;

else if (c < min2) min2 = c;

res[0] = min2 - min1; res[1] = min1; res[2] = min_p;

void max_penalty(int len1, int len2, bool is_row, int res[4]) {

int i, pc = -1, pm = -1, mc = -1, md = INT_MIN;

int res2[3];

for (i = 0; i < len1; ++i) {

if((is_row) ? row_done[i] : col_done[i]) continue;

diff(i, len2, is_row, res2);

if (res2[0] > md) {

md = res2[0]; /* max diff */

pm = i; /* pos of max diff */

mc = res2[1]; /* min cost */

pc = res2[2]; /* pos of min cost */

if (is_row) {

res[0] = pm; res[1] = pc;

}
else {

res[0] = pc; res[1] = pm;

res[2] = mc; res[3] = md;

void next_cell(int res[4]) {

int i, res1[4], res2[4];

max_penalty(N_ROWS, N_COLS, TRUE, res1);

max_penalty(N_COLS, N_ROWS, FALSE, res2);

if (res1[3] == res2[3]) {

if (res1[2] < res2[2])

for (i = 0; i < 4; ++i) res[i] = res1[i];

else

for (i = 0; i < 4; ++i) res[i] = res2[i];

return;

if (res1[3] > res2[3])

for (i = 0; i < 4; ++i) res[i] = res2[i];

else

for (i = 0; i < 4; ++i) res[i] = res1[i];

int main() {
int i, j, r, c, q, supply_left = 0, total_cost = 0, cell[4];

int results[N_ROWS][N_COLS] = { 0 };

for (i = 0; i < N_ROWS; ++i) supply_left += supply[i];

while (supply_left > 0) {

next_cell(cell);

r = cell[0];

c = cell[1];

q = (demand[c] <= supply[r]) ? demand[c] : supply[r];

demand[c] -= q;

if (!demand[c]) col_done[c] = TRUE;

supply[r] -= q;

if (!supply[r]) row_done[r] = TRUE;

results[r][c] = q;

supply_left -= q;

total_cost += q * costs[r][c];

printf(" A B C D E\n");

for (i = 0; i < N_ROWS; ++i) {

printf("%c", 'W' + i);

for (j = 0; j < N_COLS; ++j) printf(" %2d", results[i][j]);

printf("\n");

printf("\nTotal cost = %d\n", total_cost);


return 0;

Output:

A B C D E

W 0 0 50 0 0

X 30 0 20 0 10

Y 0 20 0 30 0

Z 0 0 0 0 50

Total cost = 3100

If the program is changed to this (to accomodate the second Ruby example):

#include <stdio.h>

#include <limits.h>

#define TRUE 1

#define FALSE 0

#define N_ROWS 5

#define N_COLS 5

typedef int bool;

int supply[N_ROWS] = { 461, 277, 356, 488, 393 };

int demand[N_COLS] = { 278, 60, 461, 116, 1060 };


int costs[N_ROWS][N_COLS] = {

{ 46, 74, 9, 28,

Vous aimerez peut-être aussi