00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __PROBLEM_H__
00022 #define __PROBLEM_H__
00023
00027 #include "assembler.h"
00028 #include "bt_assert.h"
00029
00030 #include <stdint.h>
00031 #include <vector>
00032 #include <set>
00033 #include <string>
00034
00035 #include <stdint.h>
00036
00037 class voxel_c;
00038 class separation_c;
00039 class separationInfo_c;
00040 class disassembly_c;
00041 class assembly_c;
00042 class gridType_c;
00043 class puzzle_c;
00044 class part_c;
00045 class solution_c;
00046 class xmlWriter_c;
00047 class xmlParser_c;
00048
00052 typedef enum {
00053 SS_UNSOLVED,
00054 SS_SOLVING,
00055 SS_SOLVED,
00056 SS_UNKNOWN
00057 } solveState_e;
00058
00059
00070 class problem_c {
00071
00072 private:
00073
00077 puzzle_c & puzzle;
00078
00084 std::vector<part_c *> parts;
00085
00089 unsigned int result;
00090
00096 std::vector<solution_c*> solutions;
00097
00104 std::set<uint32_t> colorConstraints;
00105
00111 assembler_c * assm;
00112
00117 std::string name;
00118
00122 solveState_e solveState;
00123
00130 unsigned long numAssemblies;
00131
00138 unsigned long numSolutions;
00139
00145 std::string assemblerState;
00146
00151 std::string assemblerVersion;
00152
00156 unsigned long usedTime;
00157
00165 unsigned int maxHoles;
00166
00168 void editProblem(void);
00169
00170 public:
00171
00175 problem_c(puzzle_c & puz);
00179 problem_c(puzzle_c & puz, xmlParser_c & pars);
00183 problem_c(const problem_c * prob, puzzle_c & puz);
00184
00188 ~problem_c(void);
00189
00193 void save(xmlWriter_c & xml) const;
00194
00199 const gridType_c * getGridType(void) const;
00204 gridType_c * getGridType(void);
00205
00209 const std::string & getName(void) const { return name; }
00213 void setName(std::string nm) { name = nm; }
00214
00222 void setResultId(unsigned int shape);
00226 bool resultValid(void) const;
00231 unsigned int getResultId(void) const;
00236 const voxel_c * getResultShape(void) const;
00241 voxel_c * getResultShape(void);
00243
00265 void removeShape(unsigned short shapeId);
00267 void setShapeMinimum(unsigned int shapeId, unsigned int count);
00269 void setShapeMaximum(unsigned int shapeId, unsigned int count);
00273 unsigned int getShapeMinimum(unsigned int shapeId) const;
00277 unsigned int getShapeMaximum(unsigned int shapeId) const;
00279 bool usesShape(unsigned int shapeId) const;
00284 unsigned int partNumber(void) const { return parts.size(); }
00289 unsigned int getShapeMin(unsigned int piece) const;
00294 unsigned int getShapeMax(unsigned int piece) const;
00296 unsigned int getShape(unsigned int piece) const;
00298 unsigned int getShapeId(unsigned int shape) const;
00300 const voxel_c * getShapeShape(unsigned int piece) const;
00302 voxel_c * getShapeShape(unsigned int piece);
00304 void exchangeShape(unsigned int p1, unsigned int p2);
00306 void exchangeShapeId(unsigned int s1, unsigned int s2);
00308
00314 unsigned int pieceNumber(void) const;
00316 unsigned int pieceToShape(unsigned int pieceNr) const;
00318 unsigned int pieceToSubShape(unsigned int pieceNr) const;
00320
00327 void allowPlacement(unsigned int pc, unsigned int res);
00329 void disallowPlacement(unsigned int pc, unsigned int res);
00331 bool placementAllowed(unsigned int pc, unsigned int res) const;
00333
00349 void setShapeGroup(unsigned int piece, unsigned short group, unsigned short count);
00351 unsigned short getShapeGroupNumber(unsigned int piece) const;
00353 unsigned short getShapeGroup(unsigned int piece, unsigned int groupID) const;
00355 unsigned short getShapeGroupCount(unsigned int piece, unsigned int groupID) const;
00357
00361 bool maxHolesDefined(void) const { return maxHoles != 0xFFFFFFFF; }
00363 unsigned int getMaxHoles(void) const { bt_assert(maxHoles != 0xFFFFFFFF); return maxHoles; }
00365 void setMaxHoles(unsigned int value) { bt_assert(value < 0xFFFFFFFF); maxHoles = value; }
00367 void setMaxHolesInvalid(void) { maxHoles = 0xFFFFFFFF; }
00369
00398 void removeAllSolutions(void);
00399
00412 assembler_c::errState setAssembler(assembler_c * assm);
00414 assembler_c * getAssembler(void) { return assm; }
00416 const assembler_c * getAssembler(void) const { return assm; }
00418 void incNumAssemblies(void) { bt_assert(solveState == SS_SOLVING); numAssemblies++; }
00420 void incNumSolutions(void) { bt_assert(solveState == SS_SOLVING); numSolutions++; }
00422 void addTime(unsigned long time) { bt_assert(solveState == SS_SOLVING); usedTime += time; }
00424 void addSolution(assembly_c * assm);
00428 void addSolution(assembly_c * assm, separationInfo_c * disasm, unsigned int pos = 0xFFFFFFFF);
00432 void addSolution(assembly_c * assm, separation_c * disasm, unsigned int pos = 0xFFFFFFFF);
00436 void finishedSolving(void) { solveState = SS_SOLVED; }
00437
00439 void makeUnknown(void);
00441
00451 solveState_e getSolveState(void) const { return solveState; }
00453 bool numAssembliesKnown(void) const { return solveState != SS_UNSOLVED; }
00455 unsigned long getNumAssemblies(void) const { bt_assert(solveState != SS_UNSOLVED); return numAssemblies; }
00457 bool numSolutionsKnown(void) const { return solveState != SS_UNSOLVED; }
00459 unsigned long getNumSolutions(void) const { bt_assert(solveState != SS_UNSOLVED); return numSolutions; }
00461 bool usedTimeKnown(void) const { return solveState != SS_UNSOLVED; }
00463 unsigned long getUsedTime(void) const { bt_assert(solveState != SS_UNSOLVED); return usedTime; }
00465 unsigned int solutionNumber(void) const { return solutions.size(); }
00466
00467 const solution_c * getSolution(unsigned int sol) const { bt_assert(sol < solutions.size()); return solutions[sol]; }
00468 solution_c * getSolution(unsigned int sol) { bt_assert(sol < solutions.size()); return solutions[sol]; }
00470
00471
00475 void removeSolution(unsigned int sol);
00476
00478 void sortSolutions(int by);
00480
00481 private:
00482
00483
00484 problem_c(const problem_c&);
00485 void operator=(const problem_c&);
00486
00487 };
00488
00489 #endif