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

📄 informationvector.cpp

📁 粗糙集应用软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//                   Inf5(x) = {}
//
//                   Inf2(x) < Inf1(x)    ): Inf2(x) is more general than Inf1(x).
//                   Inf3(x) !< Inf1(x)   ): Inf3(x) is not more general than Inf1(x) since they differ wrt a(x).
//                   Inf4(x) < Inf1(x)    ): Inf4(x) is more general than Inf1(x).
//
//                   Inf5(x) is the most general of all inf. vectors.
//
//                   Inf2(x) !< Inf4(x)   ): Inf2(x) is not more general than Inf4(x) since the attribute sets only partially overlap.
//                   Inf4(x) !> Inf2(x)   ): Inf4(x) is not more general than Inf2(x) since the attribute sets only partially overlap.
//                   Inf2(x) != Inf4(x)   ): Inf2(x) is not equal to Inf4(x).
//
// Comments......: Assumes that the vectors are of equal (full) length,
//                 but that for "missing" attributes, the attribute value
//                 is set to an undefined value.
//
//                 Note that with the above definition, !(a < b) and !(a == b) does not necessarily imply
//                 that (a > b).  Therefore, using the < operator for e.g. sorting is a bit dubious.
// Revisions.....:
//===================================================================

bool
InformationVector::operator<(const InformationVector &in) const {

  // Are the two objects physically equal?
  if (&in == this)
    return false;

	int j, no_attributes = in.GetNoAttributes();

	// Do the objects have the same dimensions?  If not, we cannot know whether or not
	// we are comparing the same attributes.
  if (GetNoAttributes() != no_attributes)
    return false;

	bool equal = true;

	// Examine and compare entries for each attribute.
  for (j = 0; j < no_attributes; j++) {
		int entry1 = GetEntry(j);
		int entry2 = in.GetEntry(j);
		if (entry1 != entry2)
			equal = false;
		if (entry1 == Undefined::Integer()) // Case 1: Entry 1 (this) missing, entry 2 (other) can be anything.
			continue;
		if (entry2 == Undefined::Integer()) // Case 2: Entry 1 (this) is present, entry 2 (other) is missing.
			return false;
		if (entry1 != entry2)               // Case 3: Entry 1 (this) and entry 2 (other) are both present, their values must then be equal.
			return false;
	}

	// No information vector is more defined to be more general than itself.
	if (equal)
		return false;

  return true;

}

//-------------------------------------------------------------------
// Formatting methods.
//===================================================================

//-------------------------------------------------------------------
// Method........: Format
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: If a decision table with an associated dictionary
//                 is supplied, this is used.
// Revisions.....:
//===================================================================

bool
InformationVector::Format(String &formatted, const String &name, const DecisionTable *table, bool masked) const {

	// Clear formatted string to return.
	formatted = "";

#ifdef _DEBUG
	// Check dimensions for safety.
	if (table != NULL) {
		if (GetNoAttributes() != table->GetNoAttributes(masked)) {
			Message::Error("Inconsistent dimensions detected.");
			return false;
		}
	}
#endif

	int i, no_attributes = GetNoAttributes();

	formatted += "Inf(" + name + ") = {";

	// List as attribute-value pairs.
	for (i = 0; i < no_attributes; i++) {

		// Get inf. vector entry.
		int entry = GetEntry(i);

		// Only consider non-missing entries.
		if (entry == Undefined::Integer())
			continue;

		// Get attribute name.
		String aname = (table == NULL) ? "a" + String::Format(i) : table->GetAttributeName(i, masked);

		// Get entry name.
		String ename = (table == NULL) ? String::Format(entry) : table->GetDictionaryEntry(i, entry, masked);

		// Append to formatted string.
		formatted += "(" + aname + ", " + ename + ")";

		if (i < no_attributes - 1)
			formatted += ", ";

	}

	formatted += '}';

	return true;

}

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

String
InformationVector::Format(const String &name, const DecisionTable *table, bool masked) const {

	String formatted;

	if (!Format(formatted, name, table, masked))
		formatted = Undefined::String();

	return formatted;

}

//-------------------------------------------------------------------
// Method........: FormatProlog
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: If a decision table with an associated dictionary
//                 is supplied, this is used.
// Revisions.....:
//===================================================================

bool
InformationVector::FormatProlog(String &formatted, const String &name, const DecisionTable *table, bool masked) const {

	// Clear formatted string to return.
	formatted = "";

#ifdef _DEBUG
	// Check dimensions for safety.
	if (table != NULL) {
		if (GetNoAttributes() != table->GetNoAttributes(masked)) {
			Message::Error("Inconsistent dimensions detected.");
			return false;
		}
	}
#endif

	int i, no_attributes = GetNoAttributes();

	// Each entry constitutes a Prolog fact.
	for (i = 0; i < no_attributes; i++) {

		// Get inf. vector entry.
		int entry = GetEntry(i);

		// Only consider non-missing entries.
		if (entry == Undefined::Integer())
			continue;

		// Get attribute name.
		String aname = (table == NULL) ? "a" + String::Format(i) : table->GetAttributeName(i, masked);

		// Get object name.
		String oname = name;

		// Get entry name.
		String ename = (table == NULL) ? String::Format(entry) : table->GetDictionaryEntry(i, entry, masked);

		// Uppercase is reserved for variables in Prolog.
		aname.ToLowercase();
		oname.ToLowercase();
		ename.ToLowercase();

		// Do we have to add quotes?
		if (aname.Contains(' ') || aname.Contains(','))
			aname = "\'" + aname + "\'";

		if (oname.Contains(' ') || oname.Contains(','))
			oname = "\'" + oname + "\'";

		if (ename.Contains(' ') || ename.Contains(','))
			ename = "\'" + ename + "\'";

		// Append to formatted string.
		formatted += aname + "(" + oname + ", " + ename + ").";

		if (i < no_attributes - 1)
			formatted += '\n';

	}

	return true;

}

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

String
InformationVector::FormatProlog(const String &name, const DecisionTable *table, bool masked) const {

	String formatted;

	if (!FormatProlog(formatted, name, table, masked))
		formatted = Undefined::String();

	return formatted;

}

//-------------------------------------------------------------------
// Creation methods.
//===================================================================

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

bool
InformationVector::Create(const DecisionTable &table, int object_no, bool masked) {

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

	int i, no_attributes = table.GetNoAttributes(masked);

	// Resize it.
	if (!Resize(no_attributes))
		return false;

	// Fill it.
	for (i = 0; i < no_attributes; i++) {
		if (!SetEntry(i, table.GetEntry(object_no, i, masked)))
			return false;
	}

	return true;

}

⌨️ 快捷键说明

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