-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchInWidthMethod.cpp
More file actions
88 lines (76 loc) · 2.5 KB
/
SearchInWidthMethod.cpp
File metadata and controls
88 lines (76 loc) · 2.5 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
#include "stdafx.h"
#include "SearchInWidthMethod.h"
#include "AbstractMethodSearching.h"
using namespace MethodSearching;
inline set * MethodSearching::SearchInWidthMethod::getNeighbors(ByteVector & vect) {
set* returnedset = new set();
for (auto it = getReorderedNums()->begin(); it != getReorderedNums()->end(); it++)
{
if (ByteVectorMath::HemmingLength(*it, vect) == 1) { returnedset->push_back(*it); }
}
return returnedset;
}
set * MethodSearching::SearchInWidthMethod::getMaxSet(ByteVector & vect, set * Omega, funcvalue * refmaxvalue) {
set* returnedset = new set();
//Ïîëó÷èòü ìàêñèìóì
if (Omega->size() <= 0)throw SetSizeException();
funcvalue maxvalue = elements->at(*Omega->begin());
for (auto it = Omega->begin(); it != Omega->end(); it++)
{
if (elements->at(*it) > maxvalue)
maxvalue = elements->at(*it);
}
if (refmaxvalue != nullptr)*refmaxvalue = maxvalue;
for (auto it = Omega->begin(); it != Omega->end(); it++)
{
if (elements->at(*it) == maxvalue)
returnedset->push_back(*it);
}
return returnedset;
}
MethodSearching::SearchInWidthMethod::SearchInWidthMethod(ByteVector vectors[], funcvalue values[], int size, int NSteps, int randomseed) :AbstractMethodSearching(vectors, values, size), NSteps(NSteps)
{
this->randomseed = randomseed;
srand(randomseed);
}
MethodSearching::SearchInWidthMethod::SearchInWidthMethod(const vector<ByteVector>& vectors, const vector<funcvalue>& values, int NSteps, int randomseed) :AbstractMethodSearching(vectors, values), NSteps(NSteps)
{
this->randomseed = randomseed;
srand(randomseed);
}
ByteVector MethodSearching::SearchInWidthMethod::find() {
int i = 0;
ByteVector Sstar = getReorderedNums()->at(i);
funcvalue max = elements->at(Sstar);
clog << "S*:" << Sstar << ", max:" << max << ", Omega:";
set* Omega = getNeighbors(Sstar);
printSet(Omega, elements);
clog << endl;
for (i = 1; i<NSteps; i++)
{
clog << "iter" << i << endl;
funcvalue value;
set* MaxOmega = getMaxSet(Sstar, Omega, &value);
if (value>max) {
Sstar = *MaxOmega->begin();
max = value;
delete Omega;
Omega = getNeighbors(Sstar);
}
else
{
clog << "Not bigger than max-> exit" << endl;
break;
}
clog << "S*:" << Sstar << ", f(S*):" << max << ", Omega:";
printSet(Omega, elements);
clog << ", MaxOmega:";
printSet(MaxOmega, elements);
clog << endl;
delete MaxOmega;
}
delete Omega;
clog << "answer:" << Sstar << " value:" << elements->at(Sstar) << endl;
return Sstar;
}
MethodSearching::SearchInWidthMethod::~SearchInWidthMethod() {}