Required DataType ???

A

Adam Hartshorne

Hi All,

I have the following setup, and I was wondering what would be the best
data type to achieve it.

I have a class A, that stores a list of type X's and a list of type Y's.
I also have a class B, that stores lists of type X's and type Y's .
Class A also stores a list of class B's call it list L.

Ok so I want to know how best to define type/class/struct of X and Y's
given that class A and B use them, and their job is simply to provide 2
pointers to the elements in the list L (of class B's) contained in Class A.

Adam
 
V

Victor Bazarov

Adam said:
I have the following setup, and I was wondering what would be the best
data type to achieve it.

I have a class A, that stores a list of type X's and a list of type
Y's. I also have a class B, that stores lists of type X's and type
Y's . Class A also stores a list of class B's call it list L.

Ok so I want to know how best to define type/class/struct of X and Y's
given that class A and B use them, and their job is simply to provide
2 pointers to the elements in the list L (of class B's) contained in
Class A.

Instead of describing the relationship between objects in your world,
like "I need to model the traffic with cars and passengers", you try
to describe your chosen implementation "A has a list of X and Y and
B has a list of X and Y". That is not a good way to ask for advice
on a class hierarchy. Why is the job of X and Y objects to provide
pointers to elements of L? Seems like a contrived (read: no basis in
reality) example.

If I translate to C++

struct X;
struct Y;

struct B {
std::list<X> listX;
std::list<Y> listY;
};

struct A {
std::list<X> listX;
std::list<Y> listY;
std::list<B> listL;
};

struct X {
B *pointer;
};

struct Y {
B *pointer;
};

So, this actually satisfies the requirements as stated (and they also
contain the ambiguity of whether X and Y should contain 2 pointers each
or one pointer each, and I went with the latter). But I bet you will
not be able to use it. So, again, what is the _problem_ you're trying
to solve?

To define a type means to define its interface. The interface is the
set of public members (usually functions). The functionality must come
from the way the class is to be *used*, not from what data is stores.
As soon as you realise that, all your modeling obstacles will disappear
and you will sail freely toward your goals.

Do not approach solving your problem from the wrong end. Data member
(like a list of X or B in your objects) description is actually secondary
to the class design, which is secondary to your modeling objectives.
Helping with data members cannot be successfully done without knowing
the other two parts of the process.

V
 
A

Adam Hartshorne

Victor said:
Instead of describing the relationship between objects in your world,
like "I need to model the traffic with cars and passengers", you try
to describe your chosen implementation "A has a list of X and Y and
B has a list of X and Y". That is not a good way to ask for advice
on a class hierarchy. Why is the job of X and Y objects to provide
pointers to elements of L? Seems like a contrived (read: no basis in
reality) example.

If I translate to C++

struct X;
struct Y;

struct B {
std::list<X> listX;
std::list<Y> listY;
};

struct A {
std::list<X> listX;
std::list<Y> listY;
std::list<B> listL;
};

struct X {
B *pointer;
};

struct Y {
B *pointer;
};

So, this actually satisfies the requirements as stated (and they also
contain the ambiguity of whether X and Y should contain 2 pointers each
or one pointer each, and I went with the latter). But I bet you will
not be able to use it. So, again, what is the _problem_ you're trying
to solve?

To define a type means to define its interface. The interface is the
set of public members (usually functions). The functionality must come
from the way the class is to be *used*, not from what data is stores.
As soon as you realise that, all your modeling obstacles will disappear
and you will sail freely toward your goals.

Do not approach solving your problem from the wrong end. Data member
(like a list of X or B in your objects) description is actually secondary
to the class design, which is secondary to your modeling objectives.
Helping with data members cannot be successfully done without knowing
the other two parts of the process.

V
Ok without going into too mamy specifics which I am not allowed to
reveal, I will try to state the problem with more detail.

I am setting up a markov random field. I have a class for the whole MRF
system (Class A), and a class to model a site in the MRF (Class B). Ok,
so Class A contains a list of ClassB's.

Well MRF don't operate on the sites alone, they operate on cliques
(groups of MRF sites) of different magnitude (say 1 site/2 sites/ 3sites).

I have stored the complete lists of each of the types of cliques in
Class A, call them L1,L2,L3. Also, each MRF site (Class B) must have
knowledge of which cliques they are involved in. So each MRF Site (Class
B) must itself have a list (for each type of clique) of pointers to the
elements in the complete lists (L1,L2,L3) stored in Class A.

Well I am concerned with how to form the data structure for each type of
cliques, given that they really only provide pointers to sets of
RmfSites, and must be accessible to the instance of Class A and
instances of ClassB.

Basically do I want a class/struct or something completely different? in
a seperate file to both Class A and ClassB etc or somehow stored in say
Class A but still accessible to ClassB. In fact do I actually want
ClassB and the clique structs as a classes/structs defined inside ClassA?

Adam
 
V

Victor Bazarov

Adam said:
[...]
I am setting up a markov random field. I have a class for the whole
MRF system (Class A), and a class to model a site in the MRF (Class
B). Ok, so Class A contains a list of ClassB's.

Well MRF don't operate on the sites alone, they operate on cliques
(groups of MRF sites) of different magnitude (say 1 site/2 sites/
3sites).
I have stored the complete lists of each of the types of cliques in
Class A, call them L1,L2,L3. Also, each MRF site (Class B) must have
knowledge of which cliques they are involved in. So each MRF Site
(Class B) must itself have a list (for each type of clique) of
pointers to the elements in the complete lists (L1,L2,L3) stored in
Class A.
Well I am concerned with how to form the data structure for each type
of cliques, given that they really only provide pointers to sets of
RmfSites, and must be accessible to the instance of Class A and
instances of ClassB.

Basically do I want a class/struct or something completely different?
in a seperate file to both Class A and ClassB etc or somehow stored
in say Class A but still accessible to ClassB. In fact do I actually
want ClassB and the clique structs as a classes/structs defined inside
ClassA?

It so seems that what you need is not a list of cliques in each of A
or B objects, but a list of pointers to cliques or of smart pointers
or even reference-counting pointers to cliques.

I cannot claim any understanding of MRF and related mechanisms, so
your saying "a markov random field", "cliques", falls on dear ears,
I am afraid. Therefore, without your description of how your classes
or the objects are _used_, I cannot advise you much.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top