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

📄 decisiontable.cpp

📁 粗糙集应用软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}

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

const String &
DecisionTable::GetEnumeratedDictionaryEntry(int attribute_no, int entry_no, bool masked) const {

	// No dictionary present.
	if (!HasDictionary())
		return Undefined::String();

	int unmasked;

	if (masked)
		unmasked = GetUnmaskedAttribute(attribute_no);
	else
		unmasked = attribute_no;

	return GetDictionary()->GetAttribute(unmasked)->GetEnumeratedEntry(entry_no);

}

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

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

bool
DecisionTable::GetAttributeMasks(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 i, no_attributes = GetNoAttributes(masked);

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

	for (i = 0; i < no_attributes; i++)
		masks.push_back(GetAttributeMask(i));

	return true;

}

//-------------------------------------------------------------------
// Operator......: SetAttributeMasks
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Sets the attribute masks as given by the supplied
//                 mask vector.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::SetAttributeMasks(const Vector(DecisionTable::Mask) &masks, bool safe)  {

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

	int i, no_attributes = GetNoAttributes(masked);

	// Verify dimensions.
	if (no_attributes != masks.size())
		return false;

	for (i = 0; i < no_attributes; i++) {
		if (!SetAttributeMask(i, masks[i], safe))
			return false;
	}

	return true;

}

//-------------------------------------------------------------------
// Operator......: EnableAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Enables/disables the given attribute.
//
//                 Note that the given attribute index is considered
//                 to be actual and not virtual.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::EnableAttribute(int attribute_no, bool enable, bool safe) {

	if (enable)
		return SetAttributeMask(attribute_no, MASK_ENABLED, safe);
	else
		return SetAttributeMask(attribute_no, MASK_DISABLED, safe);

}

//-------------------------------------------------------------------
// Operator......: EnableAllAttributes
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Enables/disables all attributes.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::EnableAllAttributes(bool enable, bool safe) {

	int i, no_attributes = GetNoAttributes(false);

	bool ok = true;

	for (i = 0; i < no_attributes; i++) {
		if (!EnableAttribute(i, enable, safe))
			ok = false;
	}

	return ok;

}

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

bool
DecisionTable::IsAttributeEnabled(int attribute_no) const {
	return (GetAttributeMask(attribute_no) == MASK_ENABLED);
}

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

bool
DecisionTable::IsAttributeDisabled(int attribute_no) const {
	return (GetAttributeMask(attribute_no) == MASK_DISABLED);
}

//-------------------------------------------------------------------
// Operator......: GetObjectMasks
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns (in-place) the object masks of the
//                 decision table.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::GetObjectMasks(Vector(DecisionTable::Mask) &masks) const {

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

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

	int i, no_objects = GetNoObjects(masked);

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

	for (i = 0; i < no_objects; i++)
		masks.push_back(GetObjectMask(i));

	return true;

}

//-------------------------------------------------------------------
// Operator......: SetObjectMasks
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Sets the object masks as given by the supplied
//                 mask vector.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::SetObjectMasks(const Vector(DecisionTable::Mask) &masks, bool safe)  {

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

	int i, no_objects = GetNoObjects(masked);

	// Verify dimensions.
	if (no_objects != masks.size())
		return false;

	for (i = 0; i < no_objects; i++) {
		if (!SetObjectMask(i, masks[i], safe))
			return false;
	}

	return true;

}

//-------------------------------------------------------------------
// Operator......: EnableObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Enables/disables the given object.
//
//                 Note that the given object index is considered
//                 to be actual and not virtual.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::EnableObject(int object_no, bool enable, bool safe) {

	if (enable)
		return SetObjectMask(object_no, MASK_ENABLED, safe);
	else
		return SetObjectMask(object_no, MASK_DISABLED, safe);

}

//-------------------------------------------------------------------
// Operator......: EnableAllObjects
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Enables/disables all objects.
// Comments......:
// Revisions.....:
//===================================================================

bool
DecisionTable::EnableAllObjects(bool enable, bool safe) {

	int i, no_objects = GetNoObjects(false);

	bool ok = true;

	for (i = 0; i < no_objects; i++) {
		if (!EnableObject(i, enable, safe))
			ok = false;
	}

	return ok;

}

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

bool
DecisionTable::IsObjectEnabled(int object_no) const {
	return (GetObjectMask(object_no) == MASK_ENABLED);
}

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

bool
DecisionTable::IsObjectDisabled(int object_no) const {
	return (GetObjectMask(object_no) == MASK_DISABLED);
}

//-------------------------------------------------------------------
// Index conversion (masked/unmasked) methods.
//===================================================================

//-------------------------------------------------------------------
// Method........: GetMaskedAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Maps from an actual (unmasked) attribute index to
//                 a virtual (masked) attribute index.
//
//                 As a special querying case, the unmasked query index
//                 is allowed to be one larger than the number of
//                 unmasked attributes present.
// Comments......:
// Revisions.....:
//===================================================================

int
DecisionTable::GetMaskedAttribute(int unmasked_attribute_no) const {

#ifdef _DEBUG
	if ((unmasked_attribute_no < 0) || (unmasked_attribute_no > GetNoAttributes(false))) {
		Message::Error("Attribute index out of range.");
		return Undefined::Integer();
	}
#endif

	int i;

	// Handle special case.
	if (unmasked_attribute_no == GetNoAttributes(false)) {
		int no_enabled = 0;
		for (i = 0; i < GetNoAttributes(false); i++) {
			if (IsAttributeEnabled(i))
				no_enabled++;
		}
		return no_enabled;
	}

	// For the mapping to be valid, the attribute must be valid when masked, too.
	if (!IsAttributeEnabled(unmasked_attribute_no)) {
		Message::Error("Attribute is not valid when masked, cannot perform mapping.");
		return Undefined::Integer();
	}

	int no_disabled = 0;

	// Count how many preceeding attributes that are disabled.
	for (i = 0; i < unmasked_attribute_no; i++) {
		if (!IsAttributeEnabled(i))
			no_disabled++;
	}

	return (unmasked_attribute_no - no_disabled);

}

//-------------------------------------------------------------------
// Method........: GetUnmaskedAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Maps from a virtual (masked) attribute index to
//                 an actual (unmasked) attribute index.
//
//                 As a special querying case, the masked query index
//                 is allowed to be one larger than the number of
//                 masked attributes present.
// Comments......:
// Revisions.....:
//===================================================================

int
DecisionTable::GetUnmaskedAttribute(int masked_attribute_no) const {

#ifdef _DEBUG
	if ((masked_attribute_no < 0) || (masked_attribute_no > GetNoAttributes(false))) {
		Message::Error("Attribute index out of range.");
		return Undefined::Integer();
	}
#endif

	int i, no_enabled = 0;

	// Count how many enabled attributes we have, return when we have counted high enough.
	for (i = 0; i < GetNoAttributes(false); i++) {
		if (!IsAttributeEnabled(i))
			continue;
		if (no_enabled == masked_attribute_no)
			return i;
		no_enabled++;
	}

	// Handle special case.
	if (masked_attribute_no == no_enabled)
		return GetNoAttributes(false);

	Message::Error("There does not exist as many enabled attributes as specified.");

	return Undefined::Integer();

}

//-------------------------------------------------------------------
// Method........: GetMaskedObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Maps from an actual (unmasked) object index to
//                 a virtual (masked) object index.
// Comments......: Object masking not implemented yet.
// Revisions.....:
//===================================================================

int
DecisionTable::GetMaskedObject(int unmasked_object_no) const {
	return unmasked_object_no;
}

//-------------------------------------------------------------------
// Method........: GetUnmaskedObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Maps from a virtual (masked) object index to
//                 an actual (unmasked) object index.
// Comments......: Object masking not implemented yet.
// Revisions.....:
//===================================================================

int
DecisionTable::GetUnmaskedObject(int masked_object_no) const {
	return masked_object_no;
}

//-------------------------------------------------------------------
// Operators.
//===================================================================

//-------------------------------------------------------------------
// Operator......: =
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Assignment operator.
// Comments......: Any children (derived structures) are not copied
//                 or duplicated.
// Revisions.....:
//===============================

⌨️ 快捷键说明

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