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 679 680 681 682 683 684 685 686 687 688 689
|
Function: GetCorrelatedTimeStates
Declaration: bool GetCorrelatedTimeStates(int state, intVector &states) const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetCorrelatedTimeStates
//
// Purpose:
// Gets the correlated time states for all databases in the correlation at
// the specified time state.
//
// Arguments:
// state : The state for which we want the correlated time states.
// states : The return vector for the correlated time states.
//
// Returns:
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
bool
DatabaseCorrelation::GetCorrelatedTimeStates(int state, intVector &states) const
{
bool retval = false;
if(state >= 0 && state < numStates)
{
states.clear();
int index = state;
for(size_t i = 0; i < databaseNames.size(); ++i)
{
states.push_back(indices[index]);
index += numStates;
}
retval = true;
}
return retval;
}
Function: SetNumStates
Declaration: void SetNumStates(int nstates);
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::SetNumStates
//
// Purpose:
// Sets the number of states in the correlation and adjusts the correlation
// indices.
//
// Arguments:
// nStates : The new number of states.
//
// Returns:
//
// Note: NOTE -- This method is not done and probably won't work yet.
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
void
DatabaseCorrelation::SetNumStates(int nStates)
{
if(method == IndexForIndexCorrelation)
{
intVector newIndices;
for(size_t i = 0; i < databaseNames.size(); ++i)
{
for(int j = 0; j < nStates; ++j)
{
int state = (i < databaseNStates[i]) ? i :
(databaseNStates[i]-1);
newIndices.push_back(state);
}
}
indices = newIndices;
numStates = nStates;
}
else if(method == StretchedIndexCorrelation)
{
intVector newIndices;
int maxStates = (numStates > nStates) ? numStates : nStates;
for(size_t i = 0; i < databaseNames.size(); ++i)
{
for(int j = 0; j < maxStates; ++j)
{
float t = float(j) / float(maxStates - 1);
int state = int(t * databaseNStates[i] + 0.5);
newIndices.push_back(state);
}
}
indices = newIndices;
numStates = maxStates;
}
else if(method == UserDefinedCorrelation)
{
intVector newIndices;
int currentState = 0;
int lastState = numStates - 1;
for(size_t i = 0; i < databaseNames.size(); ++i)
{
for(int j = 0; j < nStates; ++j)
{
if(j < numStates)
{
newIndices.push_back(indices[currentState++]);
}
else
newIndices.push_back(indices[lastState]);
}
lastState += numStates;
}
}
//
// Setting the number of time states for a time or cycle correlation database has
// no effect because those correlations are controlled by the times and cycles
// in the database that makes them up.
//
}
Function: AddDatabase
Declaration: void AddDatabase(const std::string &database, int nStates, const doubleVector ×, const intVector &cycles);
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::AddDatabase
//
// Purpose:
// Adds a new database to the correlation.
//
// Arguments:
// database : The name of the database to add to the correlation.
// nStates : The number of states in the database.
// times : The times for the states in the database.
// cycles : The cycles for the states in the database.
//
// Returns:
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
// Brad Whitlock, Fri Apr 1 15:17:08 PST 2005
// Fixed a rounding problem.
//
// ****************************************************************************
void
DatabaseCorrelation::AddDatabase(const std::string &database, int nStates,
const doubleVector ×, const intVector &cycles)
{
// If the database is already in the correlation, maybe we should
// remove it and then add it again in case the length changed like
// when we add time states to a file.
if(UsesDatabase(database))
return;
//
// Add the times and cycles for the new database to the correlation so
// we can access them later and perhaps use them to correlate.
//
for(int i = 0; i < nStates; ++i)
{
double t = ((i < times.size()) ? times[i] : 0.);
databaseTimes.push_back(t);
int c = ((i < cycles.size()) ? cycles[i] : 0);
databaseCycles.push_back(c);
}
if(method == IndexForIndexCorrelation)
{
if(numStates >= nStates)
{
//
// The number of states in the correlation is larger than
// the number of states in the database so we can append
// the database's states to the end of the indices and
// repeat the last frames.
//
for(int i = 0; i < numStates; ++i)
{
int state = (i < nStates) ? i : (nStates - 1);
indices.push_back(state);
}
}
else
{
//
// The number of states for the current database is larger
// than the number of states in the correlation. The correlation
// must be lengthened.
//
indices.clear();
for(size_t i = 0; i < databaseNames.size(); ++i)
{
for(int j = 0; j < nStates; ++j)
{
int state = (j < databaseNStates[i]) ? j :
(databaseNStates[i]-1);
indices.push_back(state);
}
}
// Add the new database to the correlation.
for(int i = 0; i < nStates; ++i)
indices.push_back(i);
numStates = nStates;
}
databaseNames.push_back(database);
databaseNStates.push_back(nStates);
}
else if(method == StretchedIndexCorrelation)
{
databaseNames.push_back(database);
databaseNStates.push_back(nStates);
indices.clear();
int maxStates = (numStates > nStates) ? numStates : nStates;
for(size_t i = 0; i < databaseNames.size(); ++i)
{
for(int j = 0; j < maxStates; ++j)
{
float t = float(j) / float(maxStates - 1);
int state = int(t * (databaseNStates[i] - 1) + 0.5);
indices.push_back(state);
}
}
numStates = maxStates;
}
else if(method == UserDefinedCorrelation)
{
if(numStates > nStates)
{
//
// The database being added has fewer states so we need to
// repeat the last states.
//
// We'll have to pass in the user-defined indices and append them to the indices vector
}
else
{
}
}
else if(method == TimeCorrelation)
{
databaseNames.push_back(database);
databaseNStates.push_back(nStates);
// Align time for all databases on the same time axis so we can count the
// number of times and make that be the new number of states.
std::map<double, intVector> timeAlignmentMap;
int index = 0;
for(size_t i = 0; i < databaseNames.size(); ++i)
for(int j = 0; j < databaseNStates[i]; ++j, ++index)
timeAlignmentMap[databaseTimes[index]].push_back(i);
//
// Set the condensed times vector
//
condensedTimes.clear();
for(std::map<double,intVector>::const_iterator p = timeAlignmentMap.begin();
p != timeAlignmentMap.end(); ++p)
{
condensedTimes.push_back(p->first);
}
// Now there is a map that has for each time in all of the databases
// a list of the databases that contain that time.
indices.clear();
for(size_t i = 0; i < databaseNames.size(); ++i)
{
int state = 0;
std::map<double, intVector>::const_iterator pos = timeAlignmentMap.begin();
for(; pos != timeAlignmentMap.end(); ++pos)
{
// Look to see if the current database is in the list of databases
// for the current time. If so, we need to increment the state after
// we use it.
intVector::const_iterator dbIndex =
std::find(pos->second.begin(), pos->second.end(), i);
indices.push_back(state);
if(dbIndex != pos->second.end() && state < databaseNStates[i] - 1)
++state;
}
}
numStates = timeAlignmentMap.size();
}
else if(method == CycleCorrelation)
{
databaseNames.push_back(database);
databaseNStates.push_back(nStates);
// Align cycle for all databases on the same time axis so we can count the
// number of cycles and make that be the new number of states.
std::map<int, intVector> cycleAlignmentMap;
int index = 0;
for(size_t i = 0; i < databaseNames.size(); ++i)
for(int j = 0; j < databaseNStates[i]; ++j, ++index)
cycleAlignmentMap[databaseCycles[index]].push_back(i);
//
// Set the condensed cycles vector
//
condensedCycles.clear();
for(std::map<int,intVector>::const_iterator p = cycleAlignmentMap.begin();
p != cycleAlignmentMap.end(); ++p)
{
condensedCycles.push_back(p->first);
}
// Now there is a map that has for each time in all of the databases
// a list of the databases that contain that time.
indices.clear();
for(size_t i = 0; i < databaseNames.size(); ++i)
{
int state = 0;
std::map<int, intVector>::const_iterator pos = cycleAlignmentMap.begin();
for(; pos != cycleAlignmentMap.end(); ++pos)
{
// Look to see if the current database is in the list of databases
// for the current time. If so, we need to increment the state after
// we use it.
intVector::const_iterator dbIndex =
std::find(pos->second.begin(), pos->second.end(), i);
indices.push_back(state);
if(dbIndex != pos->second.end() && state < databaseNStates[i] - 1)
++state;
}
}
numStates = cycleAlignmentMap.size();
}
}
Function: UsesDatabase
Declaration: bool UsesDatabase(const std::string &database) const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::UsesDatabase
//
// Purpose:
// Returns whether or not a database is used in the correlation.
//
// Arguments:
// database : The database we're checking for membership in the correlation.
//
// Returns: True if database is used; false otherwise.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
bool
DatabaseCorrelation::UsesDatabase(const std::string &database) const
{
return std::find(databaseNames.begin(), databaseNames.end(), database) !=
databaseNames.end();
}
Function: GetNumDatabases
Declaration: int GetNumDatabases() const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetNumDatabases
//
// Purpose:
// Returns the number of databases used in the correlation.
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
int
DatabaseCorrelation::GetNumDatabases() const
{
return databaseNames.size();
}
Function: GetCorrelatedTimeState
Declaration: int GetCorrelatedTimeState(const std::string &db, int state) const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetCorrelatedTimeState
//
// Purpose:
// Gets the correlated time state for the specified database at the given state.
//
// Arguments:
// db : The database for which we want the correlated time.
// state : The state for which we want the correlated time.
//
// Returns: The correlated time state or -1 if no correlated time state
// exists.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
int
DatabaseCorrelation::GetCorrelatedTimeState(const std::string &db, int state) const
{
int retval = -1;
if(state >= 0 && state < numStates)
{
for(size_t i = 0; i < databaseNames.size(); ++i)
{
if(databaseNames[i] == db)
{
retval = indices[i * numStates + state];
break;
}
}
}
return retval;
}
Function: GetInverseCorrelatedTimeState
Declaration: int GetInverseCorrelatedTimeState(const std::string &db, int state) const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetInverseCorrelatedTimeState
//
// Purpose:
// Gets the state in the correlation where the database "db" has a database
// state of "state".
//
// Arguments:
// db : The database for which we want the inverse correlated time.
// state : The state for which we want the inverse correlated time.
//
// Returns: The inverse correlated time state or -1 if no inverse
// correlated time state exists.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
int
DatabaseCorrelation::GetInverseCorrelatedTimeState(const std::string &db,
int dbState) const
{
int retval = -1;
for(size_t i = 0; i < databaseNames.size() && retval == -1; ++i)
{
if(databaseNames[i] == db)
{
int startIndex = i * numStates;
for(int j = 0; j < numStates; ++j)
{
if(indices[startIndex + j] == dbState)
{
retval = j;
break;
}
}
}
}
return retval;
}
Function: OutputOperator
Declaration: STATE_API ostream& operator << (ostream &os, const DatabaseCorrelation &);
Definition:
// ****************************************************************************
// Method: operator <<
//
// Purpose:
// This is a print function for DatabaseCorrelation.
//
// Arguments:
// os : The stream to print on.
// correlation : The correlation that we want to print.
//
// Returns:
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
// Brad Whitlock, Wed Apr 14 11:59:47 PDT 2004
// Fixed for Windows compiler.
//
// ****************************************************************************
ostream &
operator << (ostream &os, const DatabaseCorrelation &correlation)
{
os << "name = " << correlation.GetName().c_str() << endl;
os << "numStates = " << correlation.GetNumStates() << endl;
os << "method = " << DatabaseCorrelation::CorrelationMethod_ToString(correlation.GetMethod()).c_str() << endl;
int index = 0;
for(size_t i = 0; i < correlation.GetDatabaseNames().size(); ++i)
{
os << "database[" << i << "]=" << correlation.GetDatabaseNames()[i].c_str() << endl;
os << " numStates=" << correlation.GetDatabaseNStates()[i] << endl;
os << " times={";
for(int j = 0; j < correlation.GetDatabaseNStates()[i]; ++j)
os << correlation.GetDatabaseTimes()[index+j] << ", ";
os << "}" << endl;
os << " cycles={";
for(int j = 0; j < correlation.GetDatabaseNStates()[i]; ++j)
os << correlation.GetDatabaseCycles()[index+j] << ", ";
os << "}" << endl;
index += correlation.GetDatabaseNStates()[i];
os << " indices={";
for(int j = 0; j < correlation.GetNumStates(); ++j)
os << correlation.GetIndices()[i*correlation.GetNumStates() + j] << ", ";
os << "}" << endl;
}
const doubleVector &t = correlation.GetCondensedTimes();
if(t.size() > 0)
{
os << "condensedTimes={";
for(size_t j = 0; j < t.size(); ++j)
os << t[j] << ", ";
os << "}" << endl;
}
const intVector &c = correlation.GetCondensedCycles();
if(c.size() > 0)
{
os << "condensedCycles={";
for(size_t j = 0; j < c.size(); ++j)
os << c[j] << ", ";
os << "}" << endl;
}
return os;
}
Function: GetCondensedCycleForState
Declaration: int GetCondensedCycleForState(int state) const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetCondensedCycleForState
//
// Purpose:
// Returns the cycle for the specified state in a cycle correlation.
//
// Arguments:
// state : The state for which we want the cycle.
//
// Returns: The cycle at the specified state.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
int
DatabaseCorrelation::GetCondensedCycleForState(int state) const
{
int retval = 0;
if(state >= 0 && state < condensedCycles.size())
retval = condensedCycles[state];
return retval;
}
Function: GetCondensedTimeForState
Declaration: double GetCondensedTimeForState(int state) const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetCondensedTimeForState
//
// Purpose:
// Returns the time for the specified state in a time correlation.
//
// Arguments:
// state : The state for which we want the time.
//
// Returns: The time at the specified state.
//
// Note:
//
// Programmer: Brad Whitlock
// Creation: Sat Jan 31 19:56:11 PST 2004
//
// Modifications:
//
// ****************************************************************************
double
DatabaseCorrelation::GetCondensedTimeForState(int state) const
{
double retval = 0.;
if(state >= 0 && state < condensedTimes.size())
retval = condensedTimes[state];
return retval;
}
Function: GetMethodName
Declaration: const char *GetMethodName() const;
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetMethodName
//
// Purpose: Returns the correlation method name as a char*
//
// Programmer: Mark C. Miller
// Creation: Tuesday, May 17, 2005
//
// ****************************************************************************
const char*
DatabaseCorrelation::GetMethodName() const
{
return GetMethodNameFromMethod(GetMethod());
}
Function: GetMethodNameFromMethod
Declaration: static const char *GetMethodNameFromMethod(int m);
Definition:
// ****************************************************************************
// Method: DatabaseCorrelation::GetMethodNameFromMethod
//
// Purpose: Returns the correlation method name as a char*
//
// Programmer: Mark C. Miller
// Creation: Tuesday, May 17, 2005
//
// ****************************************************************************
const char*
DatabaseCorrelation::GetMethodNameFromMethod(int m)
{
CorrelationMethod theMethod = (CorrelationMethod) m;
switch(theMethod)
{
case IndexForIndexCorrelation: return "Index";
case StretchedIndexCorrelation: return "StretchedIndex";
case TimeCorrelation: return "Time";
case CycleCorrelation: return "Cycle";
case UserDefinedCorrelation: return "User Defined";
}
return "Unknown";
}
|