ObjectiveFunction.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include<vector>
  3. #include<string>
  4. struct Solution {
  5. std::vector<bool> bitstring;
  6. double objectiveFunctionValue;
  7. Solution();
  8. Solution(std::vector<bool> bitstring, double objectiveFunctionValue);
  9. std::string bitstringToStdString();
  10. };
  11. namespace objective {
  12. double onemaxLinear(const std::vector<bool>& bitstring);
  13. double onemaxWithTrap(const std::vector<bool>& bitstring);
  14. double onemaxTrigger(const std::vector<bool>& bitstring);
  15. class OneMax{
  16. public:
  17. std::vector<int> results;
  18. OneMax(int n, int k);
  19. void generateKStep(int k);
  20. double function(const std::vector<bool>&);
  21. };
  22. //
  23. struct Item {
  24. double value;
  25. double weight;
  26. };
  27. class KnapsackProblem {
  28. public:
  29. KnapsackProblem(double weightLimit,double limitPenalty);
  30. // List of items that can be selected
  31. std::vector<Item> itemVec;
  32. // Limit of the maximum weight that will apply the penalty
  33. double weightLimit;
  34. // The penalty for exceeding the limit
  35. double limitPenalty;
  36. double function(const std::vector<bool>&);
  37. };
  38. }