-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodi.c
More file actions
121 lines (117 loc) · 2.24 KB
/
modi.c
File metadata and controls
121 lines (117 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "solver.h"
void update_alphabeta(problem *p, tmatrix *m)
{
int i=0,j=0;
p->alpha[0] = 0;
for(i=0; i < p->angebot; i++)
{
for(j=0; j < p->nachfrage; j++)
{
if(m->matrix[i*m->y+j] == 1)
{
if(i==0)
p->beta[j] = p->matrix[i*p->nachfrage+j] - p->alpha[i];
if(p->alpha[i])
{
p->beta[j] = p->matrix[i*p->nachfrage+j] - p->alpha[i];
int x=0;
for(x=0; x < p->nachfrage; x++)
{
if(m->matrix[i*m->y+x] == 1)
{
p->beta[x] = p->matrix[i*p->nachfrage+x] - p->alpha[i];
}
}
}
if(p->beta[j])
{
p->alpha[i] = p->matrix[i*p->nachfrage+j] - p->beta[j];
int x=0;
for(x=0; x < p->angebot; x++)
{
if(m->matrix[x*m->y+j] == 1)
{
p->alpha[x] = p->matrix[x*p->nachfrage+j] - p->beta[j];
}
}
}
}
}
}
}
void relcost(problem *p, matrix *x)
{
int i=0,j=0;
for(i=0; i < p->angebot; i++)
{
for(j=0; j < p->nachfrage; j++)
{
x->matrix[i*x->y+j] = p->matrix[i*p->nachfrage+j] - p->alpha[i] - p->beta[j];
}
}
}
void print_alphabeta(problem *p)
{
int i=0;
printf("Alpha: ");
for(i=0; i < p->angebot; i++)
{
printf("%4d",p->alpha[i]);
}
printf("\n");
printf("Beta: ");
for(i=0; i < p->nachfrage; i++)
{
printf("%4d",p->beta[i]);
}
printf("\n");
}
void modi(problem *p, matrix *x)
{
matrix *rcost = newmatrix(p->angebot,p->nachfrage);
nochmal:
{
tmatrix *m = newtmatrix(x);
update_alphabeta(p,m);
relcost(p,rcost);
if(DEBUG)
{
printf("\nLoesung:\n");
printmatrix(x);
printf("\n\n");
printf("Wahrheitsmatrix zu Loesung:\n");
printtmatrix(m);
printf("\n\n");
printf("\nAlpha/Beta dazu:\n");
print_alphabeta(p);
printf("\n\n");
printf("\nRelative Kosten dazu:\n");
printmatrix(rcost);
printf("\n\n");
}
int i=0,j=0,min=0,merker_i=0,merker_j=0;
for(i=0; i < rcost->x; i++)
{
for(j=0; j < rcost->y; j++)
{
if(rcost->matrix[i*rcost->y+j] < min)
{
min = rcost->matrix[i*rcost->y+j];
merker_i = i;
merker_j = j;
}
}
}
if(min < 0)
{
node *n = newnode(merker_i,merker_j);
if(findezyklus(n,m))
{
int mfluss = maxfluss(n,x,0,BIGINT);
/* Basisloesung anpassen */
aenderloesung(x,n,mfluss,0,0);
goto nochmal;
}
}
}
}