📄 informationvector.cpp
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================
#include <stdafx.h> // Precompiled headers.
#include <copyright.h>
#include <kernel/structures/informationvector.h>
#include <kernel/structures/decisiontable.h>
//-------------------------------------------------------------------
// Methods for class InformationVector.
//===================================================================
//-------------------------------------------------------------------
// Constructors/destructor.
//===================================================================
InformationVector::InformationVector(const InformationVector &in) : Structure(in) {
}
InformationVector::InformationVector() {
}
InformationVector::~InformationVector() {
}
//-------------------------------------------------------------------
// Methods inherited from Identifier.
//===================================================================
IMPLEMENTIDMETHODS(InformationVector, INFORMATIONVECTOR, Structure)
//-------------------------------------------------------------------
// Methods inherited from Persistent.
//===================================================================
//-------------------------------------------------------------------
// Method........: Load
// Author........:
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
InformationVector::Load(ifstream &/*stream*/) {
Message::Error("Loading of a single inf. vector not implemented yet.");
return false;
}
//-------------------------------------------------------------------
// Method........: Save
// Author........:
// Date..........:
// Description...:
// Revisions.....:
//===================================================================
bool
InformationVector::Save(ofstream &/*stream*/) const {
Message::Error("Saving of a single inf. vector not implemented yet.");
return false;
}
//-------------------------------------------------------------------
// Methods inherited from Structure.
//===================================================================
void
InformationVector::Clear() {
int i;
for (i = 0; i < GetNoAttributes(); i++)
SetEntry(i, Undefined::Integer());
}
//-------------------------------------------------------------------
// Attribute administration.
//===================================================================
//-------------------------------------------------------------------
// Method........: SwapAttributes
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
InformationVector::SwapAttributes(int i, int j) {
if (i == j)
return true;
int tmp = GetEntry(i);
if (!SetEntry(i, GetEntry(j)))
return false;
if (!SetEntry(j, tmp))
return false;
return true;
}
//-------------------------------------------------------------------
// Method........: Reserve
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Reserves space, if relevant for the physical
// implementation, for an inf. vector of the
// specified size.
//
// Comments......: Since this is an abstract base class, must be
// overloaded. Default implementation does nothing.
// Revisions.....:
//===================================================================
bool
InformationVector::Reserve(int /*no_attributes*/) {
return true;
}
//-------------------------------------------------------------------
// Method........: Resize
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
InformationVector::Resize(int no_attributes) {
if (!Reserve(no_attributes))
return false;
if (GetNoAttributes() > no_attributes) {
while (GetNoAttributes() > no_attributes) {
if (!RemoveAttribute(GetNoAttributes() - 1))
return false;
}
}
else {
while (GetNoAttributes() < no_attributes) {
if (!AppendAttribute())
return false;
}
}
return true;
}
//-------------------------------------------------------------------
// Method........: AppendAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
InformationVector::AppendAttribute() {
return InsertAttribute(GetNoAttributes());
}
//-------------------------------------------------------------------
// Operators.
//===================================================================
//-------------------------------------------------------------------
// Operator......: =
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Assignment operator.
// Comments......:
// Revisions.....:
//===================================================================
InformationVector &
InformationVector::operator=(const InformationVector &in) {
// Protect against self-assignment.
if (this == &in)
return *this;
int thissize = GetNoAttributes();
int thatsize = in.GetNoAttributes();
// Does this inf. vector have too many or too few attributes?
Resize(thatsize);
int j;
// Set all entries.
for (j = 0; j < in.GetNoAttributes(); j++) {
SetEntry(j, in.GetEntry(j));
}
return *this;
}
//-------------------------------------------------------------------
// Operator......: ==
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Equality operator.
// Comments......:
// Revisions.....:
//===================================================================
bool
InformationVector::operator==(const InformationVector &in) const {
// Are the two objects physically equal?
if (&in == this)
return true;
int j, no_attributes = in.GetNoAttributes();
// Do the objects have the same dimensions?
if (GetNoAttributes() != no_attributes)
return false;
// Are all entries equal?
for (j = 0; j < no_attributes; j++) {
if (GetEntry(j) != in.GetEntry(j))
return false;
}
return true;
}
//-------------------------------------------------------------------
// Operator......: !=
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
InformationVector::operator!=(const InformationVector &in) const {
return !(*this == in);
}
//-------------------------------------------------------------------
// Operator......: <
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns true if this inf. vector is "less than"
// the input inf. vector. "Less than" in this respect
// means "more general", i.e. a subset wrt both
// attributes *and* values.
//
// Examples:
//
// Inf1(x) = {(a(x), 0), (b(x), 5), (c(x), 2)}
// Inf2(x) = {(a(x), 0), (c(x), 2)}
// Inf3(x) = {(a(x), 3), (c(x), 2)}
// Inf4(x) = {(b(x), 5), (c(x), 2)}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -