-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtn_solution.cpp
More file actions
678 lines (610 loc) · 21.7 KB
/
htn_solution.cpp
File metadata and controls
678 lines (610 loc) · 21.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
#include <vector>
#include <string>
#include <cassert>
#include <sstream>
#include <set>
#include <tr1/memory>
#include "exception.hpp"
#include "funcs.hpp"
#include "term.hpp"
#include "term_string.hpp"
#include "term_variable.hpp"
#include "term_constant.hpp"
#include "type_table.hpp"
#include "substitution.hpp"
#include "formula.hpp"
#include "formula_pred.hpp"
#include "formula_equ.hpp"
#include "formula_neg.hpp"
#include "formula_conj.hpp"
#include "operator.hpp"
#include "state.hpp"
#include "htn_task_head.hpp"
#include "htn_method.hpp"
#include "htn_domain.hpp"
#include "htn_problem.hpp"
#include "htn_solution.hpp"
/** \file htn_solution.hpp
* Declaration of HtnSolution and DecompPart classes.
*/
/** \file htn_solution.cpp
* Definition of HtnSolution and DecompPart classes.
*/
/** \class DecompPart
* A node in a hierarchical decomposition tree.
* The node has a name, which should be a method or operator name, and 0 or
* more children. This is not simply a task name, because we added the
* concept of a unique name for each method.
* This exists so that it is possible to easily print a full solution
* decomposition for the --show_trace argument to htn-solver2, which exists
* for the HTN-learner project with Dr. Qiang Yang of Hong Kong University.
*/
/** \var DecompPart::m_sName
* The name of this node.
* This is simply the task.
*/
/** \var DecompPart::m_sId
* The ID associated with this method.
* Should be an empty string for operators.
*/
/** \var DecompPart::m_vChildren
* A list of pointers to the children of this node.
* These need to be deallocated with the DecompPart.
*/
/**
* Construct a childless node from its name.
* \param p_sName IN The name of the new node.
* \param p_sId IN The ID of the new node.
*/
DecompPart::DecompPart( const std::string & p_sName,
const std::string & p_sId )
{
m_sName = p_sName;
m_sId = p_sId;
}
/**
* Construct a node as a copy of an existing one.
* Note that if there were a cyclic graph, this would crash and burn.
* \param p_Other IN The DecompPart to copy.
*/
DecompPart::DecompPart( const DecompPart & p_Other )
{
m_sName = p_Other.m_sName;
m_sId = p_Other.m_sId;
for( unsigned int i = 0; i < p_Other.m_vChildren.size(); i++ )
{
m_vChildren.push_back( new DecompPart( *p_Other.m_vChildren[i] ) );
}
}
/**
* Destruct a node.
*/
DecompPart::~DecompPart()
{
for( unsigned int i = 0; i < m_vChildren.size(); i++ )
delete m_vChildren[i];
}
/**
* Add a child to this node.
* \param p_pNew IN A pointer to the child to be added. The caller
* relinquishes constrol of this pointer, which will be deallocated with the
* DecompPart.
*/
void DecompPart::AddChild( DecompPart * p_pNew )
{
m_vChildren.push_back( p_pNew );
}
/**
* Print this node and its children to a string.
* \param p_sIndent IN A string of spaces to make this fit properly in a
* larger tree.
* \return A string containing a representation of this tree.
*/
std::string DecompPart::Print( const std::string & p_sIndent ) const
{
std::stringstream l_sRet;
l_sRet << p_sIndent << m_sName;
if( m_sId != "" )
l_sRet << " [" << m_sId << "]";
l_sRet << "\n";
if( m_vChildren.size() > 0 )
{
l_sRet << p_sIndent << "{\n";
for( unsigned int i = 0; i < m_vChildren.size(); i++ )
l_sRet << m_vChildren[i]->Print( p_sIndent + " " );
l_sRet << p_sIndent << "}\n";
}
return l_sRet.str();
}
/**
* Retrieve the list of children of this node.
* This is not quite as safe as it should be, because the caller could alter
* the contents of the pointers in the vector.
* \return The list of children of this node.
*/
const std::vector< DecompPart * > & DecompPart::GetChildren() const
{
return m_vChildren;
}
const std::string & DecompPart::GetName() const
{
return m_sName;
}
const std::string & DecompPart::GetId() const
{
return m_sId;
}
size_t DecompPart::GetMemSizeMin() const
{
size_t l_iSize = sizeof( DecompPart ) + m_sName.capacity() + m_sId.capacity() + m_vChildren.capacity() * sizeof( DecompPart * );
return l_iSize;
}
size_t DecompPart::GetMemSizeMax() const
{
size_t l_iSize = GetMemSizeMin();
for( unsigned int i = 0; i < m_vChildren.size(); i++ )
l_iSize += m_vChildren[i]->GetMemSizeMax();
return l_iSize;
}
/** \class HtnSolution
* A solution to an HTN planning problem.
* This includes the problem itself, the list of operators (leaves of the
* decomposition tree), and now a string representation of the entire tree.
*/
/**
* \var HtnSolution::m_pInitState
* The initial state of the problem.
* This is different from HtnProblem::m_pState, which is the current state as
* of any operators that have already been applied.
* This must be deallocated with the HtnSolution.
*/
/**
* \var HtnSolution::m_vOperIndices
* A list of the indices of the operators that solve the problem in the domain
* associated with the problem.
*/
/**
* \var HtnSolution::m_vOperSubs
* A list of the substitutions applied to the operators specified in
* m_vOperIndices to make them actions.
* These must be deallocated with the HtnSolution.
*/
/**
* \var HtnSolution::m_iNumDecomps
* The total number of decompositions that have been performed in this
* solution.
* This should be equivalent to the number of non-leaf nodes in the tree.
*/
/**
* \var HtnSolution::m_vDecompTree
* A list of decomposition trees, one for each top-level task in the initial
* task network of the problem.
* These must be deallocated with the HtnSolution.
*/
/**
* \var HtnSolution::m_vParents
* A list of the parents of each task in the list to accomplish. A top-level
* task will have a NULL parent, while any other task will have the method
* that decomposed into it as its parent.
* This is needed so that the new child can attach itself to the parent.
* Note that in a complete solution there are no tasks to accomplish and thus
* nothing in this list.
* Each entry in this list appears exactly once in m_vDecompTree, and will be
* deallocated there.
*/
/**
* Construct a default HtnSolution.
* This exists only for the benefit of FromShop and FromPddl.
* \param p_pDomain IN A pointer to the domain associated with the problem.
*/
HtnSolution::HtnSolution( const std::tr1::shared_ptr< HtnDomain > & p_pDomain )
: HtnProblem( p_pDomain )
{
m_iNumDecomps = 0;
m_pInitState = NULL;
}
/**
* Retrieve a pointer to a new HtnSolution from the SHOP representation of
* its problem.
* Note that the new "solution" is not a solution at all. Rather, it is a
* blank slate on which a solution may be constructed.
* The process of creating an HtnProblem just to read the problem file and
* then deleting it seems a bit inefficient, but it works.
* \param p_pDomain IN A pointer to the domain associated with this problem.
* \param p_sInput INOUT A stream containing a SHOP representation of this.
* \return A poitner to a new HtnSolution. The caller is responsible for
* deallocating it.
*/
HtnSolution * HtnSolution::FromShop( const std::tr1::shared_ptr< HtnDomain > & p_pDomain,
std::stringstream & p_sInput )
{
HtnProblem * l_pProb = HtnProblem::FromShop( p_pDomain, p_sInput );
HtnSolution * l_pRet = HtnSolution::FromProblem( l_pProb );
delete l_pProb;
return l_pRet;
}
/**
* Retrieve a pointer to a new HtnSolution from the PDDL representation of
* its problem.
* Note that the new "solution" is not a solution at all. Rather, it is a
* blank slate on which a solution may be constructed.
* The process of creating an HtnProblem just to read the problem file and
* then deleting it seems a bit inefficient, but it works.
* \param p_pDomain IN A pointer to the domain associated with this problem.
* \param p_sInput INOUT A stream containing a PDDL representation of this.
* \return A poitner to a new HtnSolution. The caller is responsible for
* deallocating it.
*/
HtnSolution * HtnSolution::FromPddl( const std::tr1::shared_ptr< HtnDomain > & p_pDomain,
std::stringstream & p_sInput )
{
HtnProblem * l_pProb = HtnProblem::FromPddl( p_pDomain, p_sInput );
HtnSolution * l_pRet = HtnSolution::FromProblem( l_pProb );
delete l_pProb;
return l_pRet;
}
/**
* Retrieve a pointer to a new HtnSolution from the HtnProblem that it
* solves.
* Note that the new "solution" is not a solution at all. Rather, it is a
* blank slate on which a solution may be constructed.
* \param p_pProblem IN A pointer to the problem to be solved.
*/
HtnSolution * HtnSolution::FromProblem( const HtnProblem * p_pProblem )
{
HtnSolution * l_pRet = new HtnSolution( p_pProblem->GetDomain() );
l_pRet->m_pState = new State( *p_pProblem->GetCState() );
l_pRet->m_pInitState = new State( *l_pRet->m_pState );
for( unsigned int i = 0; i < p_pProblem->GetNumOutstandingTasks(); i++ )
{
l_pRet->m_vOutstandingTasks.push_back( p_pProblem->GetTask( i ) );
l_pRet->m_vParents.push_back( NULL );
}
l_pRet->m_sProbName = p_pProblem->GetName();
l_pRet->m_iRequirements = p_pProblem->GetRequirements();
return l_pRet;
}
/**
* Given a list of DecompParts, a specific DecompPart from that list, and
* another list of equal length, return the entry that is in the same
* position in the second list as the given one is in the first.
* This is actually even more complicated than it sounds, because each entry
* in the list actually has child entries that need to be checked as well.
* \todo This could probably be eliminated if the DecompParts were stored in
* reference-counted pointers. Or perhaps not, because they cannot be const
* and will have different children added to them potentially.
* \param p_pToFind The search term, which must exist somewhere in p_vFindIn.
* \param p_vFindIn The list in which to search for p_pToFind.
* \param p_vEquivIn The other list from which to extract.
* \return A pointer to the proper position in p_pEquivIn.
*/
DecompPart * FindEquiv( const DecompPart * p_pToFind,
const std::vector< DecompPart * > & p_vFindIn,
const std::vector< DecompPart * > & p_vEquivIn )
{
for( unsigned int i = 0; i < p_vFindIn.size(); i++ )
{
if( p_vFindIn[i] == p_pToFind )
return p_vEquivIn[i];
DecompPart * l_pChildFind = FindEquiv( p_pToFind,
p_vFindIn[i]->GetChildren(),
p_vEquivIn[i]->GetChildren() );
if( l_pChildFind != NULL )
return l_pChildFind;
}
return NULL;
}
/**
* Construct an HtnSolution as a copy of an existing one.
* \param p_Other IN The HtnSolution to copy.
*/
HtnSolution::HtnSolution( const HtnSolution & p_Other )
: HtnProblem( p_Other ),
m_pInitState( new State( *p_Other.m_pInitState ) )
{
m_iNumDecomps = p_Other.m_iNumDecomps;
for( unsigned int i = 0; i < p_Other.m_vOperIndices.size(); i++ )
m_vOperIndices.push_back( p_Other.m_vOperIndices[i] );
for( unsigned int i = 0; i < p_Other.m_vOperSubs.size(); i++ )
m_vOperSubs.push_back( new Substitution( *p_Other.m_vOperSubs[i] ) );
for( unsigned int i = 0; i < p_Other.m_vDecompTree.size(); i++ )
m_vDecompTree.push_back( new DecompPart( *p_Other.m_vDecompTree[i] ) );
for( unsigned int i = 0; i < p_Other.m_vParents.size(); i++ )
{
if( p_Other.m_vParents[i] == NULL )
{
m_vParents.push_back( NULL );
}
else
{
DecompPart * l_pFound = FindEquiv( p_Other.m_vParents[i],
p_Other.m_vDecompTree,
m_vDecompTree );
if( l_pFound != NULL )
m_vParents.push_back( l_pFound );
else
throw Exception( E_NOT_IMPLEMENTED,
"A node's parent did not exist.",
__FILE__,
__LINE__ );
}
}
}
/**
* Destruct an HtnSolution.
*/
HtnSolution::~HtnSolution()
{
for( unsigned int i = 0; i < m_vOperSubs.size(); i++ )
delete m_vOperSubs[i];
for( unsigned int i = 0; i < m_vDecompTree.size(); i++ )
delete m_vDecompTree[i];
delete m_pInitState;
}
/**
* Apply an operator to the current task and state.
* That is, the head of the operator modulo the substition must be the same
* as the top task on the stack. Furthermore, the preconditions of the
* operator modulo the substitition must be satisfied in the current state.
* Applying this operator alters the current state and adds to the list.
* If this is a top-level task (that is, the last entry in m_vParents is NULL)
* then put a new entry in m_vDecompTree because it is a root. Otherwise,
* add this as a child of what is currently the last m_vParent. Either way,
* pop the last m_vParent.
* \param p_iOperIndexInDomain IN The index in the associated domain of the
* operator to apply.
* \param p_pNewSub IN A pointer to a substitution that grounds the operator.
* \todo This doesn't actually check the parameters!
*/
void HtnSolution::ApplyOperator( unsigned int p_iOperIndexInDomain,
const Substitution * p_pNewSub )
{
const Operator * l_pOper = m_pDomain->GetCOperator( p_iOperIndexInDomain );
if( CompareNoCase( l_pOper->GetName(), m_vOutstandingTasks.back()->GetName() ) != 0 )
{
throw Exception( E_OPER_NOT_APPLICABLE,
"Operator head does not match task.",
__FILE__,
__LINE__ );
}
FormulaP l_pPrecs( l_pOper->GetCPreconditions()->AfterSubstitution( *p_pNewSub, 0 ) );
if( !m_pState->IsConsistent( l_pPrecs ) )
{
throw Exception( E_OPER_NOT_APPLICABLE,
"Operator preconditions are not satisfied.",
__FILE__,
__LINE__ );
}
State * l_pOldState = m_pState;
m_pState = l_pOldState->NextState( m_pDomain->GetCOperator( p_iOperIndexInDomain ), p_pNewSub );
delete l_pOldState;
m_vOperIndices.push_back( p_iOperIndexInDomain );
m_vOperSubs.push_back( new Substitution( *p_pNewSub ) );
DecompPart * l_pNewPart = new DecompPart( m_vOutstandingTasks.back()->ToStr(), "" );
if( m_vParents.back() == NULL )
m_vDecompTree.push_back( l_pNewPart );
else
m_vParents.back()->AddChild( l_pNewPart );
m_vOutstandingTasks.pop_back();
m_vParents.pop_back();
}
/**
* Apply a method to the current task and state.
* That is, the head of the method modulo the substition must be the same
* as the top task on the stack. Furthermore, the preconditions of the
* method modulo the substitition must be satisfied in the current state.
* Applying this method pops the last task to be accomplished and adds its
* subtasks to this list in reverse order.
* If this is a top-level task (that is, the last entry in m_vParents is NULL)
* then put a new entry in m_vDecompTree because it is a root. Otherwise,
* add this as a child of what is currently the last m_vParent. Either way,
* pop the last m_vParent and put new entires in m_vParent of this for each
* subtask.
* \param p_iMethodIndexInDomain IN The index in the associated domain of the
* method to apply.
* \param p_pNewSub IN A pointer to a substitution that grounds the method.
* \todo This doesn't actually check the parameters!
*/
void HtnSolution::ApplyMethod( unsigned int p_iMethodIndexInDomain,
const Substitution * p_pNewSub )
{
m_iNumDecomps++;
const HtnMethod * l_pMethod = m_pDomain->GetCMethod( p_iMethodIndexInDomain );
HtnTaskHeadP l_pHead( std::tr1::dynamic_pointer_cast< HtnTaskHead >( l_pMethod->GetCHead()->AfterSubstitution( *p_pNewSub, 0 ) ) );
if( !( *l_pHead == *m_vOutstandingTasks.back() ) )
{
std::stringstream l_sMessage;
l_sMessage << "Attempt to apply method index " << p_iMethodIndexInDomain << " to task " << m_vOutstandingTasks.back()->ToStr() << "\n\n";
l_sMessage << l_pMethod->ToPddl( m_pDomain->GetRequirements() ) << "\n\n";
l_sMessage << p_pNewSub->ToStr() << "\n\n";
l_sMessage << "The head of the method, with the above substitution applied, does not match the task.\n";
throw Exception( E_METHOD_NOT_APPLICABLE,
l_sMessage.str(),
__FILE__,
__LINE__ );
}
FormulaP l_pPrecs( l_pMethod->GetCPreconditions()->AfterSubstitution( *p_pNewSub, 0 ) );
if( !m_pState->IsConsistent( l_pPrecs ) )
{
throw Exception( E_METHOD_NOT_APPLICABLE,
"Method preconditions are not satisfied.",
__FILE__,
__LINE__ );
}
DecompPart * l_pNewPart = new DecompPart( l_pHead->ToStr(), l_pMethod->GetId() );
if( m_vParents.back() == NULL )
m_vDecompTree.push_back( l_pNewPart );
else
m_vParents.back()->AddChild( l_pNewPart );
m_vOutstandingTasks.pop_back();
m_vParents.pop_back();
std::vector< HtnTaskHeadP > l_vTasks;
for( unsigned int i = 0; i < l_pMethod->GetNumSubtasks(); i++ )
{
HtnTaskHeadP l_pTask( std::tr1::dynamic_pointer_cast< HtnTaskHead >( l_pMethod->GetCSubtask( i )->AfterSubstitution( *p_pNewSub, 0 ) ) );
l_vTasks.push_back( l_pTask );
}
while( !l_vTasks.empty() )
{
m_vOutstandingTasks.push_back( l_vTasks.back() );
m_vParents.push_back( l_pNewPart );
l_vTasks.pop_back();
}
}
/**
* Retrieve the length of the plan thus far.
* \return The number of leaves in the current decomposition tree.
*/
unsigned int HtnSolution::GetPlanLength() const
{
return m_vOperIndices.size();
}
/**
* Retrieve a pointer to one of the operators in this plan.
* \param p_iIndex IN The 0-based index of the desired operator.
* \return A pointer to the desired operator.
*/
const Operator * HtnSolution::GetCOperator( unsigned int p_iIndex ) const
{
if( p_iIndex < m_vOperIndices.size() )
return m_pDomain->GetCOperator( m_vOperIndices[ p_iIndex ] );
else
{
throw Exception( E_INDEX_OUT_OF_BOUNDS,
"Bounds error.",
__FILE__,
__LINE__ );
}
}
/**
* Retrieve a pointer to one of the substitutions for the actions in this
* plan.
* \param p_iIndex IN The 0-based index of the desired substitution.
* \return A pointer to the desired substitution.
*/
const Substitution * HtnSolution::GetCSubstitution( unsigned int p_iIndex ) const
{
if( p_iIndex < m_vOperSubs.size() )
return m_vOperSubs[ p_iIndex ];
else
{
throw Exception( E_INDEX_OUT_OF_BOUNDS,
"Bounds error.",
__FILE__,
__LINE__ );
}
}
/**
* Determine whether or not this is a complete solution.
* \return Whether or not this is a complete solution.
*/
bool HtnSolution::IsComplete() const
{
return m_vOutstandingTasks.empty();
}
/**
* Retrieve a string represenation of this solution.
* \param p_bIncludeTrace IN Whether or not to print the full decomposition
* tree with the plan.
* \return A string representation of this solution.
*/
std::string HtnSolution::Print( bool p_bIncludeTrace ) const
{
std::string l_sRet = "";
State * l_pIntermediateState = NULL;
if( p_bIncludeTrace )
{
l_pIntermediateState = new State( *m_pInitState );
l_sRet += "\nState:\n";
l_sRet += l_pIntermediateState->ToStr();
l_sRet += "\n";
}
for( unsigned int j = 0; j < GetPlanLength(); j++ )
{
l_sRet += "\t( ";
l_sRet += GetCOperator( j )->GetName();
l_sRet += " ";
for( unsigned int k = 0; k < GetCOperator( j )->GetNumParams(); k++ )
{
l_sRet += GetCOperator( j )->GetCParam( k )->AfterSubstitution( *GetCSubstitution( j ), 0 )->ToStr();
l_sRet += " ";
}
l_sRet += ")\n";
if( p_bIncludeTrace )
{
l_sRet += "\nState:\n";
State * l_pTempState = l_pIntermediateState->NextState( GetCOperator( j ), GetCSubstitution( j ) );
delete l_pIntermediateState;
l_pIntermediateState = l_pTempState;
l_sRet += l_pIntermediateState->ToStr();
l_sRet += "\n";
}
}
if( p_bIncludeTrace )
{
l_sRet += "\n\nTrace\n";
for( unsigned int i = 0; i < m_vDecompTree.size(); i++ )
l_sRet += m_vDecompTree[i]->Print( "" );
}
return l_sRet;
}
/**
* Retrieve a representation of this partial solution.
* \todo This should probably be renamed.
* \return A representation of this partial solution.
*/
std::string HtnSolution::ToStr() const
{
std::string l_sRet = "";
l_sRet += " Task List:\n";
for( unsigned int i = m_vOutstandingTasks.size() - 1; i >= 0; i-- )
{
l_sRet += " ";
l_sRet += m_vOutstandingTasks[i]->ToStr();
l_sRet += "\n";
}
l_sRet += " Current Plan:\n";
for( unsigned int j = 0; j < GetPlanLength(); j++ )
{
l_sRet += " ( ";
l_sRet += GetCOperator( j )->GetName();
l_sRet += " ";
for( unsigned int k = 0; k < GetCOperator( j )->GetNumParams(); k++ )
{
l_sRet += GetCOperator( j )->GetCParam( k )->AfterSubstitution( *GetCSubstitution( j ), 0 )->ToStr();
l_sRet += " ";
}
l_sRet += ")\n";
}
return l_sRet;
}
/**
* Retrieve the number of decompositions in this solution.
* \return The number of decompositions in this solution.
*/
int HtnSolution::GetNumDecomps() const
{
return m_iNumDecomps;
}
size_t HtnSolution::GetMemSizeMin() const
{
size_t l_iSize = HtnProblem::GetMemSizeMin() + sizeof( HtnSolution ) - sizeof( HtnProblem ) + m_pInitState->GetMemSizeMin() + m_vOperIndices.capacity() * sizeof( unsigned int ) + m_vOperSubs.capacity() * sizeof( Substitution * ) + m_vDecompTree.capacity() * sizeof( DecompPart * ) + m_vParents.capacity() * sizeof( DecompPart * );
for( unsigned int i = 0; i < m_vOperSubs.size(); i++ )
l_iSize += m_vOperSubs[i]->GetMemSizeMin();
for( unsigned int i = 0; i < m_vDecompTree.size(); i++ )
l_iSize += m_vDecompTree[i]->GetMemSizeMin();
return l_iSize;
}
size_t HtnSolution::GetMemSizeMax() const
{
size_t l_iSize = HtnProblem::GetMemSizeMin() + sizeof( HtnSolution ) - sizeof( HtnProblem ) + m_pInitState->GetMemSizeMin() + m_vOperIndices.capacity() * sizeof( unsigned int ) + m_vOperSubs.capacity() * sizeof( Substitution * ) + m_vDecompTree.capacity() * sizeof( DecompPart * ) + m_vParents.capacity() * sizeof( DecompPart * );
for( unsigned int i = 0; i < m_vOperSubs.size(); i++ )
l_iSize += m_vOperSubs[i]->GetMemSizeMax();
for( unsigned int i = 0; i < m_vDecompTree.size(); i++ )
l_iSize += m_vDecompTree[i]->GetMemSizeMax();
return l_iSize;
}
const std::vector< DecompPart * > & HtnSolution::GetDecompTree() const
{
return m_vDecompTree;
}