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

📄 ksdecisiontable.cpp

📁 ROSETTA C++库是一个C++类库和例程集合
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if ((attribute_no < 0) || (attribute_no >= GetNoAttributes(masked))) {
		Message::Error("Attribute index out of range.");
		return false;
	}
#endif

	int i, attribute_no_unmasked = (masked) ? GetUnmaskedAttribute(attribute_no) : attribute_no;

	for (i = 0; i < no_objects_; i++)
		table_[i].erase(table_[i].begin() + attribute_no_unmasked);

	// Update size variables.
	no_attributes_--;

	// Deal with dictionary stuff higher up.
	if (!DecisionTable::RemoveAttribute(attribute_no, masked))
		return false;

	attribute_masks_.erase(attribute_masks_.begin() + attribute_no_unmasked);

	if (!BuildAttributeMap(attribute_no_unmasked))
		return false;

	return true;

}

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

bool
KSDecisionTable::SwapAttributes(int i, int j, bool masked) {
	return DecisionTable::SwapAttributes(i, j, masked);
}

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

DecisionTable::Status
KSDecisionTable::GetStatus(int attribute_no, bool masked) const {

#ifdef _DEBUG
	// Is the index legal?
	if ((attribute_no < 0) || (attribute_no >= GetNoAttributes(masked))) {
		Message::Error("Attribute index out of range.");
		return DecisionTable::STATUS_CONDITION;
	}
#endif

	if (attribute_no == GetNoAttributes(masked) - 1)
		return DecisionTable::STATUS_DECISION;
	else
		return DecisionTable::STATUS_CONDITION;

}

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

bool
KSDecisionTable::SetStatus(int attribute_no, DecisionTable::Status status, bool masked) {

#ifdef _DEBUG
	// Is the index legal?
	if ((attribute_no < 0) || (attribute_no >= GetNoAttributes(masked))) {
		Message::Error("Attribute index out of range.");
		return false;
	}
#endif

	if (attribute_no == no_attributes_ - 1 && status == DecisionTable::STATUS_DECISION)
		return true;

	if (attribute_no < no_attributes_ && status == DecisionTable::STATUS_CONDITION)
		return true;

	return false;

}

//-------------------------------------------------------------------
// Operator......: GetAttributeMask
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the current mask of the given attribute.
//
//                 Note that the given attribute index is considered
//                 to be actual and not virtual.
//
//                 Cf. method header of SetAttributeMask concerning how
//                 RSES handles masking and decision attribute management.
//
//                 Example:
//
//                    Actual, unmasked table:     | a b c d e
//                                             ---+-----------
//                                              0 | 5 3 1 2 8
//                                              1 | 6 7 1 7 2
//                                              2 | 4 3 6 2 8
//                                              3 | 1 2 1 2 6
//
//                    Attribute enablement mask:   {1 0 0 1 1}
//
//                    Virtual, masked table:      | a d e
//                                             ---+-------
//                                              0 | 5 2 8
//                                              1 | 6 7 2
//                                              2 | 4 2 8
//                                              3 | 1 2 6
//
//                    Actual table:
//
//                      GetNoAttributes(false) returns 5.
//                      GetEntry(2, 1, false) returns (2, b), i.e. 3.
//
//                    Virtual table:
//
//                      GetNoAttributes(true) returns 3.
//                      GetEntry(2, 1, true) returns (2, d), i.e. 2.
//
// Comments......:
// Revisions.....:
//===================================================================

DecisionTable::Mask
KSDecisionTable::GetAttributeMask(int attribute_no) const {

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

	return attribute_masks_[attribute_no];

}

//-------------------------------------------------------------------
// Method........: SetAttributeMask
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Enables or disables the given attribute.
//
//                 Note that the given attribute index is considered
//                 to be actual and not virtual.
//
//                 If the safety flag is specified (true by default), it
//                 is checked that the table has no children. This
//                 since it may be unsafe to alter the masking of a table
//                 with children, since these chldren may refer to the
//                 parent table through indices, which necessarly change
//                 if the masking changes.
// Revisions.....:
//===================================================================

bool
KSDecisionTable::SetAttributeMask(int attribute_no, DecisionTable::Mask mask, bool safe) {

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

	if (mask == GetAttributeMask(attribute_no))
		return true;

	// If the table has children, altering the enablement masking may cause
	// trouble, since most children store the masked indices that were valid when
	// they were created.
	if (safe && HasChildren()) {
		Message::Error("A table with children cannot have its masking altered.");
		return false;
	}

	attribute_masks_[attribute_no] = mask;

	return BuildAttributeMap(attribute_no);

}

//-------------------------------------------------------------------
// Operator......: GetObjectMask
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the current mask of the given object.
//
//                 Note that the given object index is considered
//                 to be actual and not virtual.
//
// Comments......: Object masking not implemented yet.
// Revisions.....:
//===================================================================

DecisionTable::Mask
KSDecisionTable::GetObjectMask(int object_no) const {

#ifdef _DEBUG
	if ((object_no < 0) || (object_no >= GetNoObjects(false))) {
		Message::Error("Object index out of range.");
		return DecisionTable::MASK_DISABLED;
	}
#endif

	return DecisionTable::MASK_ENABLED;

}

//-------------------------------------------------------------------
// Operator......: SetObjectMask
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Sets the mask of the given object.
//
//                 Note that the given object index is considered
//                 to be actual and not virtual.
//
//                 If the safety flag is specified (true by default), it
//                 is checked that the table has no children. This
//                 since it may be unsafe to alter the masking of a table
//                 with children, since these chldren may refer to the
//                 parent table through indices, which necessarly change
//                 if the masking changes.
//
// Comments......: Object masking not implemented yet.
// Revisions.....:
//===================================================================

bool
KSDecisionTable::SetObjectMask(int object_no, DecisionTable::Mask mask, bool safe) {

#ifdef _DEBUG
	if ((object_no < 0) || (object_no >= GetNoObjects(false))) {
		Message::Error("Object index out of range.");
		return false;
	}
#endif

	if (mask == GetObjectMask(object_no))
		return true;

	// If the table has children, altering the enablement masking may cause
	// trouble, since most children store the masked indices that were valid when
	// they were created.
	if (safe && HasChildren()) {
		Message::Error("A table with children cannot have its masking altered.");
		return false;
	}

	return false;

}

//-------------------------------------------------------------------
// 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
KSDecisionTable::GetUnmaskedObject(int masked_object_no) const {

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

	return masked_object_no;

}

//-------------------------------------------------------------------
// Method........: GetUnmaskedAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Maps from a virtual (masked) attribute index to
//                 an actual (unmasked) attribute index.
// Comments......:
// Revisions.....:
//===================================================================

int
KSDecisionTable::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

	return attribute_map_[masked_attribute_no];

}

//-------------------------------------------------------------------
// Local methods.
//===================================================================

//-------------------------------------------------------------------
// Method........: BuildAttributeMap
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Creates the map from masked indices to unmasked
//                 indices for attributes.
// Comments......:
// Revisions.....:
//===================================================================

bool
KSDecisionTable::BuildAttributeMap(int attribute_no) {

	// Clear current map.
	attribute_map_.erase(attribute_map_.begin(), attribute_map_.end());
	attribute_map_.reserve(no_attributes_);

	int i;

	// For now, rebuild map from scratch.
	for (i = 0; i < no_attributes_; i++) {
		if (attribute_masks_[i] == DecisionTable::MASK_ENABLED) {
			attribute_map_.push_back(i);
		}
	}

	return true;

}

⌨️ 快捷键说明

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