PartitionSolver.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: Statistics.h
  24. /*---------------------------------------------------------------------------*/
  25. /* EA Pacific */
  26. /* Confidential Information */
  27. /* Copyright (C) 2001 - All Rights Reserved */
  28. /* DO NOT DISTRIBUTE */
  29. /*---------------------------------------------------------------------------*/
  30. /* Project: RTS3 */
  31. /* File name: PartitionSolver.h */
  32. /* Created: John K. McDonald, Jr., 4/2/2002 */
  33. /* Desc: General purpose partition problem-solver */
  34. /* Revision History: */
  35. /* 4/12/2002 : Initial creation */
  36. /*---------------------------------------------------------------------------*/
  37. #pragma once
  38. #ifndef _H_PARTITIONSOLVER_
  39. #define _H_PARTITIONSOLVER_
  40. // INCLUDES ///////////////////////////////////////////////////////////////////
  41. // DEFINES ////////////////////////////////////////////////////////////////////
  42. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  43. // FORWARD DECLARATIONS ///////////////////////////////////////////////////////
  44. typedef std::pair<ObjectID, UnsignedInt> PairObjectIDAndUInt;
  45. typedef std::pair<ObjectID, ObjectID> PairObjectID;
  46. // the first unsigned int is the identifying nugget, while the second is the size of the nugget
  47. typedef std::vector<PairObjectIDAndUInt> EntriesVec;
  48. // the first unsigned int is the identifying nugget, while the second is the size of the hole we get to fill
  49. typedef std::vector<PairObjectIDAndUInt> SpacesVec;
  50. // the first ObjectID is the id of the entry, while the second is the id of the hole
  51. typedef std::vector<PairObjectID> SolutionVec;
  52. enum SolutionType
  53. {
  54. PREFER_FAST_SOLUTION = 0,
  55. PREFER_CORRECT_SOLUTION = 0x7FFFFFFF
  56. };
  57. class PartitionSolver
  58. {
  59. protected:
  60. SolutionType m_howToSolve;
  61. EntriesVec m_data;
  62. SpacesVec m_spacesForData;
  63. SolutionVec m_currentSolution;
  64. UnsignedInt m_currentSolutionLeftovers;
  65. SolutionVec m_bestSolution;
  66. public:
  67. PartitionSolver(const EntriesVec& elements, const SpacesVec& spaces, SolutionType solveHow);
  68. // Solve could potentially take a LONG TIME (as in NEVER complete). This problem is NP-complete.
  69. void solve(void);
  70. const SolutionVec& getSolution( void ) const;
  71. };
  72. #endif /* _H_PARTITIONSOLVER_ */