00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <FlowShopOpCrossoverQuad.h>
00014
00015
00016 std::string FlowShopOpCrossoverQuad::className() const
00017 {
00018 return "FlowShopOpCrossoverQuad";
00019 }
00020
00021
00022 bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2)
00023 {
00024 bool oneAtLeastIsModified;
00025
00026 unsigned int point1, point2;
00027 do
00028 {
00029 point1 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
00030 point2 = rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
00031 } while (fabs((double) point1-point2) <= 2);
00032
00033 FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
00034 FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
00035
00036 if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
00037 {
00038
00039 _flowshop1.value(offspring1);
00040 _flowshop2.value(offspring2);
00041
00042 oneAtLeastIsModified = true;
00043 }
00044 else
00045 {
00046
00047 oneAtLeastIsModified = false;
00048 }
00049
00050 return oneAtLeastIsModified;
00051 }
00052
00053
00054 FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2)
00055 {
00056 FlowShop result = _parent1;
00057 std::vector<bool> taken_values(result.size(), false);
00058 if (_point1 > _point2)
00059 std::swap(_point1, _point2);
00060
00061 for (unsigned int i=0 ; i<=_point1 ; i++)
00062 {
00063
00064 taken_values[_parent1[i]] = true;
00065 }
00066 for (unsigned int i=_point2 ; i<result.size() ; i++)
00067 {
00068
00069 taken_values[_parent1[i]] = true;
00070 }
00071
00072 unsigned int i = _point1+1;
00073 unsigned int j = 0;
00074 while (i<_point2 && j<_parent2.size())
00075 {
00076 if (! taken_values[_parent2[j]])
00077 {
00078 result[i] = _parent2[j];
00079 i++;
00080 }
00081 j++;
00082 }
00083 return result;
00084 }