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

📄 scaler.cpp

📁 ROSETTA C++库是一个C++类库和例程集合
💻 CPP
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........: 960307
// Description...:
// Revisions.....:
//===================================================================

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

#include <kernel/algorithms/scaler.h>
#include <kernel/algorithms/keyword.h>

#include <kernel/structures/decisiontable.h>
#include <kernel/structures/dictionary.h>
#include <kernel/structures/attribute.h>
#include <kernel/structures/floatattribute.h>
#include <kernel/structures/integerattribute.h>
#include <kernel/structures/stringattribute.h>

#include <kernel/basic/vector.h>
#include <kernel/basic/algorithm.h>

#include <kernel/utilities/creator.h>
#include <kernel/utilities/mathkit.h>

#include <kernel/system/fstream.h>
#include <kernel/system/math.h>

//-------------------------------------------------------------------
// Methods for class Scaler.
//===================================================================

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

Scaler::Scaler() {
	SetMode(MODE_SAVE);
	SetFilename(Undefined::String());
	MaskSymbolic(true);
}

Scaler::~Scaler() {
}

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

IMPLEMENTIDMETHODS(Scaler, SCALER, Algorithm)

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

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

String
Scaler::GetParameters() const {

	String parameters;

	parameters += Keyword::Mode();
	parameters += Keyword::Assignment();
	parameters += GetString(GetMode());

	parameters += Keyword::Separator();

	parameters += Keyword::Mask();
	parameters += Keyword::Assignment();
	parameters += String::Format(MaskSymbolic());

	if (GetMode() == MODE_DISCARD)
		return parameters;

	parameters += Keyword::Separator();

	parameters += Keyword::Filename();
	parameters += Keyword::Assignment();
	parameters += GetFilename();

	return parameters;

}

//-------------------------------------------------------------------
// Method........: GetOutputFilenames
// Author........: Aleksander 豩rn
// Date..........:
// Description...: See Algorithm::GetOutputFilenames method.
// Comments......:
// Revisions.....:
//===================================================================

bool
Scaler::GetOutputFilenames(Vector(String) &filenames) const {

	if (!Algorithm::GetOutputFilenames(filenames))
		return false;

	if (GetMode() == MODE_SAVE)
		filenames.push_back(GetFilename());

	return true;

}

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

bool
Scaler::SetParameter(const String &keyword, const String &value) {

	// Set mode.
	if (keyword == Keyword::Mode()) {
		if (value == GetString(MODE_DISCARD))
			return SetMode(MODE_DISCARD);
		if (value == GetString(MODE_SAVE))
			return SetMode(MODE_SAVE);
		if (value == GetString(MODE_LOAD))
			return SetMode(MODE_LOAD);
		return false;
	}

	// Set filename.
	if (keyword == Keyword::Filename())
		return SetFilename(value);

	// Set masking flag.
	if (keyword == Keyword::Mask() && value.IsBoolean())
		return MaskSymbolic(value.GetBoolean());

	// Unknown keyword.
	return false;

}

//-------------------------------------------------------------------
// Method........: IsApplicable
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns true if the algorithm is applicable to the
//                 structure, false otherwise.
// Comments......:
// Revisions.....:
//===================================================================

bool
Scaler::IsApplicable(const Structure &structure, bool /*warn*/) const {
	return structure.IsA(DECISIONTABLE);
}

//-------------------------------------------------------------------
// Masking methods.
//===================================================================

//-------------------------------------------------------------------
// Method........: GetTemporaryAttributeMasks
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns (in-place) how the maskvector would be if all
//                 symbolic condition attributes were disabled.
// Comments......:
// Revisions.....:
//===================================================================

bool
Scaler::GetTemporaryAttributeMasks(const DecisionTable &table, Vector(DecisionTable::Mask) &masks) const {

	// Clear current contents.
	masks.erase(masks.begin(), masks.end());

	// Operate on an unmasked table.
	bool masked = false;

	// Get table dimensions.
	int no_attributes = table.GetNoAttributes(masked);

	// Reserve space to avoid spurious allocations.
	masks.reserve(no_attributes);

	int i;

	for (i = 0; i < no_attributes; i++) {
		if (table.IsSymbolic(i, masked) && table.IsCondition(i, masked))
			masks.push_back(DecisionTable::MASK_DISABLED);
		else
			masks.push_back(table.GetAttributeMask(i));
	}

	return true;

}

//-------------------------------------------------------------------
// Method........: GetAttributeMasks
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns (in-place) the attribute masks of the
//                 given decision table.
// Comments......:
// Revisions.....: A

⌨️ 快捷键说明

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