?? discernibilitymatrix.cpp
字號:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================
#include <stdafx.h> // Precompiled headers.
#include <copyright.h>
#include <kernel/structures/discernibilitymatrix.h>
#include <kernel/structures/decisiontable.h>
#include <kernel/structures/generalizeddecision.h>
#include <kernel/utilities/partitionkit.h>
#include <kernel/utilities/discerner.h>
#include <kernel/utilities/iokit.h>
#include <kernel/utilities/mathkit.h>
#include <kernel/basic/algorithm.h>
#include <kernel/system/fstream.h>
//-------------------------------------------------------------------
// Constructors/destructor.
//===================================================================
//-------------------------------------------------------------------
// Method........: Constructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Copy constructor
// Comments......:
// Revisions.....:
//===================================================================
DiscernibilityMatrix::DiscernibilityMatrix(const DiscernibilityMatrix &in) : Structure(in) {
// Copy index stuff.
map_ = in.map_;
representatives_ = in.representatives_;
matrix_.reserve(in.matrix_.size());
int i;
// Duplicate matrix entries.
for (i = 0; i < in.matrix_.size(); i++) {
if (in.matrix_[i] == NULL)
matrix_.push_back(NULL);
else
matrix_.push_back(new Bits(*(in.matrix_[i])));
}
}
//-------------------------------------------------------------------
// Method........: Constructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Empty constructor
// Comments......:
// Revisions.....:
//===================================================================
DiscernibilityMatrix::DiscernibilityMatrix() {
}
//-------------------------------------------------------------------
// Method........: Destructor.
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
DiscernibilityMatrix::~DiscernibilityMatrix() {
Clear();
}
//-------------------------------------------------------------------
// Methods inherited from Identifier.
//===================================================================
IMPLEMENTIDMETHODS(DiscernibilityMatrix, DISCERNIBILITYMATRIX, Structure)
//-------------------------------------------------------------------
// Methods inherited from Persistent.
//===================================================================
//-------------------------------------------------------------------
// Method........: Load
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
DiscernibilityMatrix::Load(ifstream &/*stream*/) {
return false;
}
//-------------------------------------------------------------------
// Method........: Save
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
DiscernibilityMatrix::Save(ofstream &stream) const {
return Save(stream, '-');
}
//-------------------------------------------------------------------
// Methods inherited from Structure.
//===================================================================
//-------------------------------------------------------------------
// Method........: Duplicate
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
Structure *
DiscernibilityMatrix::Duplicate() const {
return new DiscernibilityMatrix(*this);
}
//-------------------------------------------------------------------
// Method........: Clear
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
void
DiscernibilityMatrix::Clear() {
int i;
// Delete matrix entries.
for (i = matrix_.size() - 1; i >= 0; i--) {
if (matrix_[i] != NULL)
delete matrix_[i];
}
map_.erase(map_.begin(), map_.end());
representatives_.erase(representatives_.begin(), representatives_.end());
matrix_.erase(matrix_.begin(), matrix_.end());
}
//-------------------------------------------------------------------
// New methods.
//===================================================================
//-------------------------------------------------------------------
// Method........: AllocateMatrix
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Physically allocates the matrix. Enables lazy
// allocation.
//
// Returns true if allocation took place.
//
// Comments......: The matrix framework (representatives and mappings)
// must have been initialized prior to calling this
// method!
// Revisions.....:
//===================================================================
bool
DiscernibilityMatrix::AllocateMatrix() {
// Matrix already allocated?
if (HasAllocatedMatrix())
return false;
// How many unique objects are there?
unsigned int no_unique_objects = representatives_.size();
if (no_unique_objects == 0)
return false;
Message::Debug("Allocating matrix...");
unsigned int tmp0 = no_unique_objects;
unsigned int tmp1 = no_unique_objects - 1;
// How many entries will there be in the reduced matrix? Try to avoid numerical overflows.
if (tmp0 % 2 == 0)
tmp0 /= 2;
else
tmp1 /= 2;
unsigned int no_entries = tmp0 * tmp1;
// Erase, resize and initialize.
matrix_.erase(matrix_.begin(), matrix_.end());
matrix_.reserve(no_entries);
matrix_.insert(matrix_.end(), no_entries, NULL);
return true;
}
//-------------------------------------------------------------------
// Method........: GetDimension
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the logical (or reduced, physical)
// dimension of the matrix.
// Comments......:
// Revisions.....:
//===================================================================
int
DiscernibilityMatrix::GetDimension(bool reduced) const {
if (!reduced)
return map_.size();
else
return representatives_.size();
}
//-------------------------------------------------------------------
// Method........: GetEntry
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....: A
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -