-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathPerturb.cpp
70 lines (50 loc) · 1.52 KB
/
Perturb.cpp
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
#include "Perturb.h"
using namespace std;
void
Perturb(vector<vector<int>*> &S_pert,vector<int> &leftover,
vector<int> &used_rolls,vector<int> &variety,
vector<int> &rlenght,vector<int> &lpiece,vector<int> &lot_s,
int pertubs) {
int i = 0;
int orig;
int dst;
int piece;
int npieces = lpiece.size();
vector<int>* pieceSet;
while( i < pertubs ){
orig = (int)round(random()) % npieces;
dst = (int)round(random()) % npieces;
piece = (int)round(random()) % npieces;
int nitems_orig = (*S_pert[orig])[piece];
if (orig == dst){
continue;
}
if (nitems_orig == 0){
continue;
}
//Si el movimiento es permitido
if (checkMove(dst,piece,npieces,
&S_pert,&lpiece,&variety)) {
int* bestCut;
//======Destino
if ((*S_pert[dst])[piece] == 0)
variety[dst]++;
pieceSet = S_pert[dst];
(*pieceSet)[piece] += min(lot_s[piece],nitems_orig);
bestCut = bestCutting(*pieceSet,rlenght,lpiece);
leftover[dst] = bestCut[0];//leftofer en dst
used_rolls[dst] = bestCut[1]; //rolls usados en dst
delete [] bestCut;
//======Origen
pieceSet = S_pert[orig];
(*pieceSet)[piece] -= min(lot_s[piece],nitems_orig);
bestCut = bestCutting(*pieceSet,rlenght,lpiece);
leftover[orig] = bestCut[0];//leftofer en dst
used_rolls[orig] = bestCut[1]; //rolls usados en dst
if ((*S_pert[orig])[piece] == 0)
variety[orig]--;
delete [] bestCut;
i++;
}
}
}