Solved

Aggregation of classes

Posted on 2009-05-13
12
703 Views
Last Modified: 2013-12-14
Experts,

I have 3 classes simulation, actor and conversation. The actor is specific to the simulation and the conversation is actor specific. Therefore, I think that class aggregation is the way to go.
I am struggling with the issue i am faced with...
I am parsing files to find all the actors within a simulation. The simulation paramaters are defined by the user in main(). As the code scans and finds the 'actors' - i want to create a new actor object of the simulation class with its own attributes. Then, I want the code to run through again and to create conversation objects that are specific to the relevant actors. Therefore, I need to be able to access the correct actor and insert conversation object during runtime. This is all done dynamically.

The end result is that I want to be able to do all sorts of operations on the stored objects. For example:
1) Count the number of radio_comms per simulation
2) Count the number of radio_comms per actor of a simulation
3) Compare number of radio_comms for 1 actor across 2 different simulations
4) Calculate total time of radio_comms of each actor for a particular simulation (conversation length is a data member of the conversation objects)

Does anyone know how I might start this? I think i want to use an STL map or set to store the objects as they are produced in main - but I am confused as to the class constructor definitions that will allow the analysis above.

Simondo


class radio_comms										// Radio communication objects are objects of the actor class

{														

private:

	string type;										// SENT OR RECIEVED

	string party;										// Other party to the interaction

	string start;										// Start Time of the interaction

	string finish;										// Finish time of the interaction

	float f_start;										// Start time as a float in seconds

	float f_finish;										// Finish time as a float in seconds

	float duration;										// Duration of the interaction in seconds

public:

	radio_comms(string t, string p, string s, string f, string d): type(t),		// 5 argument constructor

		party(p),start(s),finish(f)

	{

			int hh, mm, ss, mmm;						

			sscanf(start.c_str(),"%d:%d:%d:%d",&hh,&mm,&ss,&mmm);

			f_start=(((hh * 60) + mm) * 60) + ss + (mmm / 1000.0);

			sscanf(finish.c_str(),"%d:%d:%d:%d",&hh,&mm,&ss,&mmm);

			f_finish=(((hh * 60) + mm) * 60) + ss + (mmm / 1000.0);

			duration=f_finish-f_start;

	}													

};
 

class sector													// Sector class creating objects to store sector information and functions

{																// Sector class are objects of the simulation class

	private:

		string ident;				// i.e APPNE, J, S, DIR

		string user;				// i.e civil

		string control;				// i.e en_route

		float vert_sep;				// i.e 1000

		float lat_sep;				// i.e 8.0

		float freq;					// i.e 111.10

	public:							// Sector constructor

		sector(string i, string u, string c, float v, float l, float f):ident(i),user(u),control(c),vert_sep(v),lat_sep(l),freq(f)

		{}

		sector():ident(""),user(""),control(""),vert_sep(0.0),lat_sep(0.0),freq(0.0)		// No argument constructor

		{}

		void extract_data()

		{}

		friend bool operator<(const sector&, const sector&);								// Operator overload declarator

		

		friend bool operator < (const sector& s1, const sector& s2)	

		{

			if(s1.user==s2.user)										// If Users is the same, compare by identity

				return(s1.ident<s2.ident)?true:false;					// Compare by identity (ie APPNE to J)

			return (s1.user<s2.user)?true:false;						// Else compare by user (i.e civil to military)

		}

		void display()													// Display object contents

		{

			cout<<endl<<ident<<"\t"<<user<<"\t"<<control<<"\t"<<vert_sep<<"\t"<<lat_sep<<"\t"<<freq;

		}
 

};	
 

class actor														// Actors are objects of the simulation class and stores objects of controller information

{

private:

		string position;										// APPNE/DIR etc. This is linked to the SECTOR CLASS

		string type;											// EC or PC. 

		string filepath;										// The filepath for corresponding audio file that holds all conversations

		radio_comms rcoms;										// Radio communication objects
 

public:

		actor(string p, string t, string f):position(p),type(t), filepath(f)

		{}

		void extract_data()

		{}

		friend bool operator<(const actor&, const actor&);					// Operator overload declarator

		

		friend bool operator < (const actor& a1, const actor& a2)	

		{

			if(a1.type==a2.type)											// If types are the same, compare by identity

				return(a1.position<a2.position)?true:false;					// Compare by position (ie APPNE to J)

			return (a1.type<a2.type)?true:false;							// Else compare by type

		}

		void display()														// Display object contents

		{

			cout<<endl<<position<<"\t"<<type<<"\t";

		}

};
 

class simulation												// The base class to hold basic simulation data

{

private:														// Better to use protected so members of derived classes have access

	string name;												// i.e PANSA

	string date;												// i.e 03122008

	string scenario;											// i.e AREFBASE													

	string sim_start_time;										// i.e 09:15

	sector sec;													// Sector objects

	actor act;													// Actor objects

	aircraft acft;												// Aircraft objects
 

public:

	simulation():name(""),date(""),scenario(""),sim_start_time("")	// No argument constructor

	{}

	simulation(string n, string d, string s, string st):name(n),date(d),scenario(s),sim_start_time(st) // 4 argument constructor

	{}

	

	void show_sim()const

	{

		cout<<"Simulation:" << " " << name << endl;

		cout<<"Date:" << " " << date << endl;

		cout<<"Scenario:" << " "  << scenario << endl;

		cout<<"Start Time:" << " " << sim_start_time << endl;

	}
 

};

Open in new window

0
Comment
Question by:simondopickup
  • 5
  • 3
  • 2
  • +1
12 Comments
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24381259
A radio_comm is a conversation?

>>1) Count the number of radio_comms per simulation

Actor needs an std::list<radio_comm>

>>2) Count the number of radio_comms per actor of a simulation

Actor might need an integer counting total radio_comms

>>3) Compare number of radio_comms for 1 actor across 2 different simulations

Either run one simulation per program run, and store the data to a file, then use the file for summarization, or use a list of simulations, and the simulation class will need an std::map<actor_id, int> which will hold a count of radio_comms per actor.

>>4) Calculate total time of radio_comms of each actor for a particular simulation (conversation length is a data member of the conversation objects)

Use actor.radio_comm_list, if the radio_comm class has conversation_length, iterate through actor.radio_comm_list and sumarize.
0
 
LVL 40

Expert Comment

by:mrjoltcola
ID: 24381449
Not sure if that was what you were looking for, but since I may not be able to respond until tomorrow, if you are wondering about syntax...


#include <list>


class conversation;

class actor {
   private:
      std::list<conversation> conversations;

};



See a very good tutorial on STL here with plenty of samples:

http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html

0
 

Author Comment

by:simondopickup
ID: 24382445
So i actually need to include my embedded class definition (actor) within the surrounding class (simulation)?. If i create a new actor object, i need to ensure that the actor is explicitly linked to the simulation that is currently being 'looked at' during run time.

Later on - I need to be able to scan all the simulations one by one and make different conclusions (not just those listed in the original post) about the actors and conversations in each simulation. Should I also be storing simulation objects in STL containers?

0
 
LVL 1

Assisted Solution

by:maartennieber
maartennieber earned 100 total points
ID: 24382795
1. Can you explain what you mean by: "i want to create a new actor object of the simulation class with its own attributes"?

2. It might be helpful to focus a bit more on the interfaces of your classes. Before asking yourself: "how does a actor store a conversation?" you could ask "what interface should an actor offer to allow associating it with a conversation?" For example: actor could have an addConversation function. This would help to have a better (rough) idea of the class design. (Here I'm assuming that you are creating a program that you will maintain in the future as well, not a fast tool to do some work that you will then forget about).

3. Since the same actors can appear in many simulations, it makes sense to me to store actors in a separate container (an actorManager class for example) and store references to these actors (such as actor ids) in the simulation class.

4. Also, is it really necessary to run two loops? (one for finding actors and one for finding conversations).
When finding a conversation in the input file, can't you use something like:

Actor* actor = currentSimulation.getActorWith(actor_id);
if (actor == null)
{
    actor = currentSimulation.addActorWith(actor_id);
}

and then add the conversation to the actor?

5. About the statistics that you want to obtain: I would first focus on having the raw data properly stored in the objects. Once you have that, it is probably easy to add some functions to your classes that extract the desired statistics.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24382855
I have still problems to understand the object model.

(A) What is a simulation?

(B) What is an actor (in a simulation?) ?

(C) What is a conversation and how relates it to the radio_comm?

to (A)
As far as I understand you might have 1 or 2 simulations (but not hundreds?).

to (B)
Is actor a person? If so, why there is no name attribute or some other ID? How will you compare actors across simulations if each simulation has one (single) actor and these were different instances of actors rather than can refer to the same actor.

to (C)
If radio_comm is a conversation why each actor has only one radio_comm as member? And isn't it possible that two actors were acting in the same radio_comm? How will you handle that if not with independent lists (containers) for each class?

Note, the principle of OOP (object-orientated programming) is object identity. So if you need the *same* actor in two simulations you should not create two actor instances having the same name but create only one actor and make a relation from simulation 1 to that actor and from simulation 2 as well. That relation can be made by pointer or by ID where the latter is better. In our sample you either would have a list of actor names in the simulation or otherway round a list of simulation names with the actor (you normally won't have both as this requires additional efforts especially in case of changes). I would prefer to have a list of actors at the simulation as I prefer to wag the dog's tail but not to wag the tail's dog.

Same considerations apply to radio_comms though I don't know what that actually is (within the limitations of your simulation).




0
 

Author Comment

by:simondopickup
ID: 24383014
I have still problems to understand the object model.

(A) What is a simulation?
>> This is the top level of my data parsing structure. For each simulation (there can be about 10 of them - the script will need to parse an .ini file that denotes all the simulations. Each simulation has a name, a date and scenario which i was going to store as data members of the simulation class.

(B) What is an actor (in a simulation?) ?
>> For each simulation, there could be dozens of actors. The actors may not be the same across each simulation - but sometimes they are - it depends on the simulation design. The actors are found by the parsing script as it scans through the logs. The parsing script will only scan one simulations worth of data at a time. Each actor object has a name and a type data member and I want to make actor objects as an aggregate of the 'current' simulation object, as and when they are found.

(C) What is a conversation and how relates it to the radio_comm?

>> Sorry - a conversation IS a radio_comm. My fault. Each actor engages in hundreds of radio_comms in each simulation. I want to store each radio_comm as an object of an actor when they are found. The parsing script executes in a manner such that all possible radio_comms for a newly created actor will be scanned before moving on to find another actor. Radio_comms objects have data members of start_time, end_time, party (i.e the individual recieving the transmission - this is NOT another actor) and the duration of the transmission.

to (A)
As far as I understand you might have 1 or 2 simulations (but not hundreds?).
>> Correct.

to (B)
Is actor a person? If so, why there is no name attribute or some other ID? How will you compare actors across simulations if each simulation has one (single) actor and these were different instances of actors rather than can refer to the same actor.
>> The actors needs an ID - you are right. I was assuming that the actor's position would serve as an ID, but there can be 2 or more actors of the same position. So an ID needs adding.

to (C)
If radio_comm is a conversation why each actor has only one radio_comm as member? And isn't it possible that two actors were acting in the same radio_comm? How will you handle that if not with independent lists (containers) for each class?
>> As above, I need some sort of container to store the radio_comms for each actor as they are found by the parsing script.

Note, the principle of OOP (object-orientated programming) is object identity. So if you need the *same* actor in two simulations you should not create two actor instances having the same name but create only one actor and make a relation from simulation 1 to that actor and from simulation 2 as well.
>> That is exactly what I am trying to do. But wouldnt this mean that my actor would NOT be embedded class of a simulation?  Each radio communication should be associated with a particular actor too.

 That relation can be made by pointer or by ID where the latter is better. In our sample you either would have a list of actor names in the simulation or otherway round a list of simulation names with the actor (you normally won't have both as this requires additional efforts especially in case of changes). I would prefer to have a list of actors at the simulation as I prefer to wag the dog's tail but not to wag the tail's dog.
>> I need to be able to query actor radiocomms across simulations to evaluate how the actors radiocomms varied across each sim. However, I would also need to compare all the actors radiocomms across just 1 simulation.

Same considerations apply to radio_comms though I don't know what that actually is (within the limitations of your simulation).
>> I hope I have clarified.


0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:simondopickup
ID: 24383063
Just to be clear..a simulation is a real event - from which we have GIGABYTES of logs about the actors and the radio_comms in which they are involved (amongst many other things)
0
 

Author Comment

by:simondopickup
ID: 24383215
I have done a diagram to show how I am interpeting this thread currently. Especially the OOP notion of creating individual objects that can be referenced to other objects. In my problem, there can be different actors in different simulations - and thus once an instance of an actor object is created - he will not be created again. However, radio comms are specific to a simulation AND actor instance. SO for example, to evaluate the total time the APPNE was talking in Simulation 1, i would need to sum all the radio_comm 'duration' data members that were linked to simulation 1 and actor APPNE.

is my problem any clearer? I am currently looking at embedded classes since the ACTORS are 'part of' a simulation and the radio_comms are 'PART OF' an actor???

No i am not sure whether my dog is yapping up the incorrect shrub.

Object--Structures.jpg
0
 
LVL 1

Expert Comment

by:maartennieber
ID: 24383383
I'd say actors are NOT part of a simulation, since the same actor can appear in multiple simulations.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 400 total points
ID: 24383408
>>>> I want to make actor objects as an aggregate of the 'current' simulation object, as and when they are found.
If the actor can be part of two or more simulation object it shouldn't be an aggregate of the simulation. Instead for each new actor you got from your logs add a new instance to a global actor container and add the ID of the actor to the list of actors which is a member of the simulation.

>>>> Each radio communication should be associated with a particular actor too
If your diagram is correct there are never two actors in the same radio_comm. Hence you could store the ID of the actor as member of a radio_comm (backward or parent relation) or have a list of radio_comm objects as member of the author.

Tio handle the global containers for simulations and authors I would suggest to have an *application* or *manager* class which is a singleton class and where the containers were member.

class application
{
    vector<simulation> all_sims;
    map<string, author>  all_auths;

};

class simulation
{
     vector<string> author_ids;
};

class author
{
    vector<radio_comm> rcomms;
};

Note, each class managing a container would provide functions to operate on that container or make queries on it.

Note, the radio_comm not necessarily needs an author_id as member but it wouldn't harm.
0
 

Author Comment

by:simondopickup
ID: 24394847
I am still working on implementing the structure that itsmeandnobodyelse suggested. I will award points but expect more questions as the practicalities of it dawn.

Thanks
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24398340
1) Count the number of radio_comms per simulation

int application::getRadioCommsCountPerSimulation(int simId)
{
    if (simId < 0 || simId >= all_sims.size()) return -1;  // wrong simId
    return all_sims[simId].getRadioCommsCount();
}

int simulation::getRadioCommsCount()
{
    vector<string>::iterator ita;
    int count = 0,
    for (ita = author_ids.begin(); ita != author_ids.end(); ++ita)
    {
         author a & = theApp.getAuthorFromMap(*ita);   // get author from application
         if (author.isempty()) return -1;   // wrong author in simulation
         count += a.getRadioCommsCount();
     }
    return count;
}

int author::getRadioCommsCount()
{
    return (int)rcomms.size();
}

author & application::getAuthorFromMap(const string & authorId)
{
     return all_auths[authorId];   // that would create an empty author if not already exists
}

bool author::isempty()
{
     return author_id.empty();  // assuming author_id is a string member of class author
}


0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now