Possible library submissions: fuzzy logic library, new container

I am trying to determine if there might be any interest in a couple of possible library submissions. Both ideas were very useful and instrumental for many C++ development projects that I was doing for the last years. The fuzzy logic library is a simple, pure C++, optimized for speed, practical implementation of the fuzzy logic calculations that DOES NOT attempts to comply with the FCL(Fuzzy Control Language) standard (like IEC 1131). It CANNOT load FCL files. Instead similar to the Boost Spirit framework it provides a syntax that enables fuzzy logic rules to be written exclusively in C++. Compiled fuzzy model specifications are immediately executable. A snippet of what this syntax currently looks like is at the end of this message. The other idea is the “sparse array” container. Working for securities trading industry I used it innumerable number of times. It is useful in situations where there is a set of entities identified by integer(unsigned) numbers. Most often the numbers are identity keys in a database, a protocol field ids, etc. The potential range of the numbers makes it impractical to use a C++ array or the STL <vector>. On the other hand the average percentage of the keys that are really used in an application relative to the potential range is often less then 5% and there are huge holes of unused keys between zero and max(used key). The data elements or pointers to objects are kept in a structure similar to a balanced B-tree. Elements are directly accessed by an index operator. Access involves only a few arithmetic and redirection operations. When storing a new element that is outside of the range provided by exiting data structure the structure bilds itself up extending the indes range enough to accommodate a new index value. Existing data are never physically moved like in the STL vector. So, all references/pointers/iterators referencing existing elements are never invalidated. Feel free to comment. Fuzzy model syntax sample: ======================================== #include "TestModel.h" using namespace Fuzzy; // test model definition TestModel::TestModel(string file): Model(file), angle(-1), velocity(-1), speed(-1) { // fuzzy variables definitions created by the base class (Fuzzy::Model) // Input/Output methods; Input/Output arguments are refs // to double scalar variables Var& Angle = Input(angle); Var& Vlcty = Input(velocity); Var& Speed = Output(speed); // membership functions definitions created by fuzzy variables // Term method; Term method takes curve name as an argument; // cureve names are defined in the Fuzzy::Model curve definition // file MemFun& AngleNegHigh = Angle.Term("AngleNegHigh"); MemFun& AngleNegLow = Angle.Term("AngleNegLow"); MemFun& AngleZero = Angle.Term("AngleZero"); MemFun& AnglePosLow = Angle.Term("AnglePosLow"); MemFun& AnglePosHigh = Angle.Term("AnglePosHigh"); MemFun& VlctyNegHigh = Vlcty.Term("VelocityNegHigh"); MemFun& VlctyNegLow = Vlcty.Term("VelocityNegLow"); MemFun& VlctyZero = Vlcty.Term("VelocityZero"); MemFun& VlctyPosLow = Vlcty.Term("VelocityPosLow"); MemFun& VlctyPosHigh = Vlcty.Term("VelocityPosHigh"); MemFun& SpeedNegHigh = Speed.Term("AngleNegHigh"); MemFun& SpeedNegLow = Speed.Term("AngleNegLow"); MemFun& SpeedZero = Speed.Term("AngleZero"); MemFun& SpeedPosLow = Speed.Term("AnglePosLow"); MemFun& SpeedPosHigh = Speed.Term("AnglePosHigh"); // these are the model rules; syntax is pretty strightforward; // rules look like operator >> where lhs is the condition and // rhs is the conclusion; // lhs and rhs have to be in parens if they contain more then // one term because of the c++ operators precedence rules; // conclusion may be a comma separated list of output terms // in parens ((AngleZero and VlctyZero)or(AnglePosLow and VlctyNegLow)or(AngleNegLow and VlctyPosLow)) >> SpeedZero; ((AngleZero and VlctyNegLow)or(AngleNegLow and VlctyZero)) >> SpeedNegLow; ((AnglePosLow and VlctyZero)or(AngleZero and VlctyPosLow)) >> SpeedPosLow; ((AngleZero and VlctyNegHigh)or(AngleNegHigh and VlctyZero)) >> SpeedNegHigh; ((AnglePosHigh and VlctyZero)or(AngleZero and VlctyPosHigh)) >> SpeedPosHigh; } TestModel::~TestModel() { } void TestModel::run(double a, double v, double &s) { // we assign scalar variables to class members angle = a; velocity = v; speed = s; // then run the model // it should be pretty fast as it all designed to preallocate // all the needed large objects in the model constructor Model::run(); // and assign the values of output variables s = speed; }

Alex Shafir wrote:
The other idea is the “sparse array” container. Working for securities trading industry I used it innumerable number of times. It is useful in situations where there is a set of entities identified by integer(unsigned) numbers. Most often the numbers are identity keys in a database, a protocol field ids, etc. The potential range of the numbers makes it impractical to use a C++ array or the STL <vector>. On the other hand the average percentage of the keys that are really used in an application relative to the potential range is often less then 5% and there are huge holes of unused keys between zero and max(used key). The data elements or pointers to objects are kept in a structure similar to a balanced B-tree. Elements are directly accessed by an index operator. Access involves only a few arithmetic and redirection operations. When storing a new element that is outside of the range provided by exiting data structure the structure bilds itself up extending the indes range enough to accommodate a new index value. Existing data are never physically moved like in the STL vector. So, all references/pointers/iterators referencing existing elements are never invalidated.
Very interesting, but how is it substantially different from std::map? -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Wed, 25 Jun 2008 16:45:23 -0500, Alex Shafir wrote:
The other idea is the “sparse array” container. Working for securities trading industry I used it innumerable number of times. It is useful in situations where there is a set of entities identified by integer(unsigned) numbers. Most often the numbers are identity keys in a database, a protocol field ids, etc. The potential range of the numbers makes it impractical to use a C++ array or the STL <vector>. On the other hand the average percentage of the keys that are really used in an application relative to the potential range is often less then 5% and there are huge holes of unused keys between zero and max(used key). The data elements or pointers to objects are kept in a structure similar to a balanced B-tree. Elements are directly accessed by an index operator. Access involves only a few arithmetic and redirection operations. When storing a new element that is outside of the range provided by exiting data structure the structure bilds itself up extending the indes range enough to accommodate a new index value. Existing data are never physically moved like in the STL vector. So, all references/pointers/iterators referencing existing elements are never invalidated.
Catching up on my emails, I've just seen this one. I also have a sparse array implementation I've been thinking about introducing to Boost (I did send a message to the boost mailing list some time ago, but various commitments since then have prevented me from going forward with it). It's a policy-based sparse array implementation which allows for specification of how bounds are handled, how iterators behave, how default values are handled, and the underlying storage mechanism. I've tried to make it as flexible as possible within the bounds of those policies. If there is interest I could try tidying up the documentation and sorting out a Boost submission. Spencer
participants (3)
-
Alex Shafir
-
David Abrahams
-
Spencer Collyer