CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2015
    Posts
    500

    coming up with data structure for the algorithm

    Hello,

    I have list of unique keys for the mobile cells, and i can get the info about the cells, from those keys.

    Also these cells are grouped into sites, based on the parent id info available on the cell.

    Now i have a algo, may be initially i will tell the simple alog, later on share the actual one.

    In the attached pics(siteplan),

    i want to group the cells, under each site. Now lets say site1 is the centre site as specified by the user. And from the list of cells in the region, i comeup that, site1 has C1, C2, and C3 cells.
    And c2 has C22 as neighbour with distance d1
    C1 has C31 as neighbour.
    C3 has C52 as neighbour.

    I got a req saying that, i need to give the same TAC for the site which has shortest neighbour to site1. Then assign the TAC for next lowest distance, until the TAC1 < maxTAC. Then for the next one assign TAC2,..etc

    Alll i now have a set of keylists..Could you give me some hint on the data structure i can come up.

    I am thinking of map of tuple, may be initially combile all cells that belong to same site.

    map( site, < c1, neigh id, distance>
    < >
    )

    is this ok ?
    And a
    Attached Images Attached Images   

  2. #2
    Join Date
    May 2015
    Posts
    500

    Re: coming up with data structure for the algorithm

    As of now the code i have is :


    Code:
    	std::map<int, std::set<int>> m_SiteToCellsMap;
    
    bool TAC_Manager::PopulateCellsAndNeighbours()
    {
    	
    	for (std::list<int>::iterator cellIter = keyList.begin(); cellIter != keyList.end(); ++cellIter)
    	{
    		MultiTechCell* pCell = dynamic_cast<MultiTechCell*>(BusinessObjects::BO_DBHelper::instance().Find(OT_MULTI_TECH_CELL, (*cellIter)));
    		if (pCell)
    		{
    			result = true;
    			int CellKey = 0;
    			int TopParentKey = 0;
    
    				CellKey = pCell->GetKey();
    				m_SiteToCellsMap[pCell->GetParent()->GetKey()].insert(CellKey);

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: coming up with data structure for the algorithm

    Sorry for the late reply - which is possibly less helpful than expected. We've pulled out with work at the moment...

    IMO, I'd take a sub-set of the data, work through it be hand using pen/paper trying different ways/techniques etc to achieve the required result. When you're happy with doing the problem by hand, then look at how you're done it, design suitable data structure(s) and then the program. The last thing I'd do is to just start coding and see how it works out.

    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    May 2015
    Posts
    500

    Re: coming up with data structure for the algorithm

    Thanks a lot kaud. Yes i do understand, busy with work.
    Just i thought sharing this, because while sharing, i get some more ideas

    i.e ok, this is more of design issue. As you adviced, trying to be clear before coding.

    Thanks a lot
    pdk

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: coming up with data structure for the algorithm

    I understand that to begin with you have keys that you want to organize into a structure, but once this is done what happens next?

  6. #6
    Join Date
    Feb 2017
    Posts
    677

    Re: coming up with data structure for the algorithm

    Do you want to find the shortest cell distance between two sites? Then you just calculate all possible cell distances one by one and keep the shortest so far. You don't need a data structure for that.

  7. #7
    Join Date
    May 2015
    Posts
    500

    Re: coming up with data structure for the algorithm

    Thanks wolle, i found an example and followed that. I tried to add a predicate which sorts itself

  8. #8
    Join Date
    Feb 2017
    Posts
    677

    Re: coming up with data structure for the algorithm

    Quote Originally Posted by pdk5 View Post
    I tried to add a predicate which sorts itself
    You don't have to sort anything. Of course you can store all distances and then sort them to find the shortest. But you really just need to keep track of one distance, the shortest_so_far. Each time you calculate a new distance, you compare it with the shortest_so_far. If it is shorter, it becomes the new shortest_so_far otherwise you continue with the next distance. In the end the shortest_so_far is the shortest distance of all distances you have calculated.

    I don't quite understand what you have and what you want to accomplish but it's important not to complicate things. The simpler the better in my view.
    Last edited by wolle; December 4th, 2020 at 04:11 PM.

  9. #9
    Join Date
    May 2015
    Posts
    500

    Re: coming up with data structure for the algorithm

    Thankyou wolle.

    Btw, now i have comeup with some vague flowchart and started coding.

    Code:
    	std::unordered_map<int, std::set<TACNeighbourData> > m_SiteNeighbours;
    
    
    
    
    for (auto configData : m_pTACWizData->m_TacPlanData.GetConfigData())
    	{	
    		__int64 nCurrentPagecountTacArea(0);
    		int nCurrentNumSitesTacArea(0);
    		int nCurrentTAC = configData.GetTAC();
    		int nMaxSitesInTAC = configData.GetNumSites();
    		__int64 nMaxPagingCountInTAC = configData.GetPagingCounts();
    		CString sCentralsite = configData.GetCentralSite();
    
    		// Move the central site to the first one in the map
    		// TODO_PDK: check Will the map always iterate in the sequence ?
    		for (auto [site, neighbours] : m_SiteNeighbours)
    		{
    			// Assign the TAC, only if the site has not been assigned the TAC
    			if (m_SiteToTacList[site] == NO_TAC_VALUE)
    			{
    				for (auto neigh : neighbours)
    				{
    					MultiTechCell* pCell = dynamic_cast<MultiTechCell*>(BusinessObjects::BO_DBHelper::instance().Find(OT_MULTI_TECH_CELL, (neigh.m_CellKey)));
    					if (pCell)
    					{
    						int TopParentKey = NO_TAC_VALUE;
    						const auto* pNode = static_cast<const MultiTechNode*>(pCell->GetParent());
    						if (pNode)
    						{
    							TopParentKey = pNode->GetKey();
    
    							// Get this neighbours parent site and check if the paging count of all its child nodes is not exceeding
    							for (auto nCell : m_SiteToCellsMap[TopParentKey])
    							{
    								MultiTechCell* pCell = dynamic_cast<MultiTechCell*>(BusinessObjects::BO_DBHelper::instance().Find(OT_MULTI_TECH_CELL, (nCell)));
    
    								LTECellParams* pLteCopyCellParams(pCell->GetParams<LTECellParams>());	ASSERT_ONCE(pLteCopyCellParams);
    								CellCarrierBase* pLteCopyCellCarrierBase = pLteCopyCellParams->GetSingleCarrier();
    								LTECellCarrier* pLteCopyCellCarrier = dynamic_cast<LTECellCarrier*>(pLteCopyCellCarrierBase);	ASSERT_ONCE(pLteCopyCellCarrier);
    
    								nCurrentPagecountTacArea += pLteCopyCellCarrier->GetPagingCount();
    							}
    
    							if ((nCurrentPagecountTacArea < nMaxPagingCountInTAC) && (nCurrentNumSitesTacArea < nMaxSitesInTAC))
    							{
    								m_TacToSiteIdentifierList.insert(std::make_pair(nCurrentTAC, TopParentKey));
    							}
    						}
    					}
    				}
    				nCurrentNumSitesTacArea++;
    			}
    		}
    Basically in the m_SiteNeighbours, i list all sites that site is neighbor with. This excludes neighbourcells within same site.

    Now i have a question, in m_SiteNeighbours, can i move a particular site id to the front, so it iterates first ?

  10. #10
    Join Date
    May 2015
    Posts
    500

    Re: coming up with data structure for the algorithm

    Basically to have a simple view of pbm, i have:
    Out of m_SiteNeighbours, i have a centre site stored. I want to process that first.


    for (auto [site, neighbours] : m_SiteNeighbours)
    {

    // PROCESSING
    }

    Execute the //PROCESSING for the particular site in the m_SiteNeighbours map first. Rest all sites need to execute //PROCESSING later.


    Sorry for making it so complicated. One way is the erase that id, and reinsert at the beginning.

    So i did the following

    moved // PRECEESSING to function process_function, then

    for (central site)
    process_function();

    for (auto [site, neighbours] : m_SiteNeighbours)
    process_function();
    Last edited by pdk5; December 4th, 2020 at 05:37 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured