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

📄 rsesorthogonalscaler.cpp

📁 粗慥集成算法集合 ,并有详细的文档资料和测试数据处
💻 CPP
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........: 960628
// Description...:
// Revisions.....:
//===================================================================

#include <stdafx.h> // Precompiled headers.
#include <copyright.h>

#include <kernel/rses/algorithms/rsesorthogonalscaler.h>

#include <kernel/rses/structures/rsesdecisiontable.h>

#include <kernel/rses/library/tscal.h>
#include <kernel/rses/library/tdtable.h>
#include <kernel/rses/library/err.h>

#include <kernel/utilities/creator.h>

//-------------------------------------------------------------------
// Methods for class RSESOrthogonalScaler.
//===================================================================

//-------------------------------------------------------------------
// Constructors/destructor.
//===================================================================

//-------------------------------------------------------------------
// Method........: Constructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

RSESOrthogonalScaler::RSESOrthogonalScaler() {
}

//-------------------------------------------------------------------
// Method........: Destructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

RSESOrthogonalScaler::~RSESOrthogonalScaler() {
}

//-------------------------------------------------------------------
// Methods inherited from Identifier.
//===================================================================

IMPLEMENTIDMETHODS(RSESOrthogonalScaler, RSESORTHOGONALSCALER, OrthogonalScaler)

//-------------------------------------------------------------------
// Methods inherited from Algorithm.
//===================================================================

//-------------------------------------------------------------------
// Method........: IsApplicable
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

bool
RSESOrthogonalScaler::IsApplicable(const Structure &structure, bool warn) const {

	if (!structure.IsA(RSESDECISIONTABLE))
		return false;

	Handle<RSESDecisionTable> rsestable = dynamic_cast(RSESDecisionTable *, const_cast(Structure *, &structure));

	return !rsestable->HasExceededMaximumDimensions(warn);

}

//-------------------------------------------------------------------
// Methods inherited from OrthogonalScaler.
//===================================================================

//-------------------------------------------------------------------
// Method........: Discretize
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

DecisionTable *
RSESOrthogonalScaler::Discretize(DecisionTable &table) const {

	// Check if input is of expected type.
	if (!IsApplicable(table))
		return NULL;

	// Cast to verified type.
	Handle<RSESDecisionTable> wrapper = dynamic_cast(RSESDecisionTable *, &table);

	TDTable *input;
	TDTable *output;

	bool masked = true;

	// Is there anything to scale?
	if ((wrapper->GetNoObjects(masked) == 0) || (wrapper->GetNoAttributes(masked) == 0)) {
		Message::Error("The decision table is empty and cannot be scaled.");
		return NULL;
	}

	// Get raw RSES table.
	input = wrapper->decisiontable_;

	if (input == NULL) {
		Message::Error("The input RSES decision table is invalid.");
		return NULL;
	}

	// Specify scaling algorothm (cfr. RSES technical doc.)
	int method = 0;

	// Perform scaling.
	try {
		TScaler scaler;
		if (GetMode() == MODE_DISCARD) {   // Scale and discard the resulting cuts.
			output = scaler.Scal(input, method);
		}
		else if (GetMode() == MODE_SAVE) { // Scale and save the resulting cuts to the named file.
			output = scaler.Scal(input, const_cast(char *, GetFilename().GetBuffer()), method);
		}
		else {
			Message::Error("Unknown scaling mode.");
			return NULL;
		}
	}
	catch (Error &error) {
		Message::RSESError("An error occurred during scaling of decision table.", error.GetMessage());
		return NULL;
	}

	// Was an output produced?
	if (output == NULL) {
		Message::Error("The RSES scaler did not produce a valid output.");
		return NULL;
	}

	// Is there no need to create a new wrapper?
	if (output == input)
		return wrapper.Release();

	// Create a wrapper for the result.
	Handle<RSESDecisionTable> result = Creator::RSESDecisionTable();

	// Clean up and prepare the result wrapper.
	delete result->decisiontable_;
	result->decisiontable_ = output;

	return result.Release();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -