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