OptimVars.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* Copyright (C) 2014 Carlos Aguilar Melchor, Joris Barrier, Marc-Olivier Killijian
  2. * This file is part of XPIR.
  3. *
  4. * XPIR is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * XPIR is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with XPIR. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef DEF_OPTIVAR
  18. #define DEF_OPTIVAR
  19. #include <assert.h>
  20. #include <limits>
  21. #include <math.h>
  22. #include <algorithm>
  23. #include <string>
  24. // Fitness method to compute total value
  25. // SUM: sum all costs
  26. // MAX: sum the max costs of the client and server pipelines
  27. enum FitnessType {SUM, MAX, CLOUD};
  28. // Struct with the variables fixed before calling the optimizer
  29. // These are considered mandatory (alternatives will not be explored)
  30. struct FixedVars
  31. {
  32. // Number of files in the database
  33. uint64_t n;
  34. // Length in bits of the largest file in the database
  35. uint64_t l;
  36. // Client and Server upload Throughputs
  37. double Tupc, Tups;
  38. // Client and Server download Throughputs
  39. double Tdoc, Tdos;
  40. // Force crypto parameters manually
  41. std::string manual_crypto_params;
  42. // Security bits requested for the cryptosystem
  43. unsigned int k;
  44. // Minimum level of recursion tested
  45. unsigned int dMin;
  46. // Maximum level of recursion tested
  47. unsigned int dMax;
  48. // Maximum aggregation tested (0 = no limit, 1 = no aggregation)
  49. unsigned int alphaMax;
  50. // Fitness method to compute total cost
  51. FitnessType fitness;
  52. };
  53. // Object with the variables TO BE fixed by the optimizer
  54. // Also contains the costs associated to these variables:
  55. // Query generation and transmission, reply generation, transmission and decryption
  56. // Able to compute from these costs the total cost for a given fitness method
  57. // Variables start uninitialized and costs to the maximum values of the corresponding types
  58. // Each time a set of variables improves the total cost in a test, variables and costs are updated
  59. class OptimVars
  60. {
  61. private:
  62. // Enum type to make more readable the cost array indexes
  63. enum {GENQ, SENDQ, GENR, SENDR, DECR, COST_NBR};
  64. // Array containing the costs for the different operations of a PIR instance
  65. double costs[COST_NBR];
  66. double limits[COST_NBR];
  67. // Fitness method (redundant with the one of fixed vars but useful for
  68. // comparison operators to know what fitness method is used to compare)
  69. FitnessType fitness;
  70. FixedVars fixedVars;
  71. public:
  72. // Default constructor (fitness=MAX)
  73. OptimVars();
  74. // More specific constructor and destructor
  75. OptimVars(FitnessType fitness);
  76. OptimVars(FixedVars fixed_vars);
  77. OptimVars(FitnessType fitness_, FixedVars fixed_vars);
  78. ~OptimVars();
  79. // Method to change the fitness method
  80. void setType(FitnessType fitness_);
  81. // Getters and setters for individual costs
  82. double getGenQ();
  83. void setGenQ(double GenQ);
  84. double getSendQ();
  85. void setSendQ(double SendQ);
  86. double getGenR();
  87. void setGenR(double GenR);
  88. double getSendR();
  89. void setSendR(double SendR);
  90. double getDecR();
  91. void setDecR(double DecR);
  92. unsigned int getAlpha();
  93. void setAlpha(unsigned int alpha_);
  94. unsigned int getDim();
  95. void setDim(unsigned int d_);
  96. FixedVars getFixedVars();
  97. void setFixedVars(FixedVars fixed_vars);
  98. // Variables TO BE fixed by the optimizer (don't feel like doing getters and setters)
  99. unsigned int alpha;
  100. unsigned int d;
  101. std::string crypto_params;
  102. // Getter for total value for the current fitness method
  103. virtual double getValue();
  104. // Access and comparison operators
  105. double operator[](unsigned int i);
  106. bool operator<(OptimVars &other);
  107. bool operator>(OptimVars &other);
  108. bool operator==(OptimVars &other);
  109. void operator=(OptimVars &other);
  110. // Reset all costs to the maximum (to restart optimization)
  111. void reset();
  112. };
  113. #endif