⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 discernibilitymatrix.cpp

📁 粗糙集应用软件
💻 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 + -