I am looking for some recommendations on the methodology / data structure / algorithmic approach to the problem that I am trying to solve.
I am writing a special spreadsheet application in VBA. A spreadsheet is a timetable and quote document. The user enters the basic information on labor planning, which is then used to create several different worksheets / documents with the initial data presented in various formats / formats.
Honestly, Excel is not the right application for this, but this is what users want and are comfortable with, and I know VBA well, so I'm stuck.
The key data entered by the user is in the lower format, essentially, for each daily work call for each role.
βββββββ¦βββββββββ¦βββββββββββββββββ¦βββββββββββββββββ¦ββββββββββββββββββββ β QTY β ROLE β START β END β DESCRIPTION β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/15/17 08:00a β 6/15/17 04:00p β Travel to Prep β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/16/17 08:00a β 6/16/17 06:00p β Prep β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/17/17 08:00a β 6/17/17 07:00p β Prep β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 3 β Rigger β 6/18/17 06:00a β 6/18/17 05:00p β Travel to Install β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 3 β Rigger β 6/19/17 08:00a β 6/20/17 01:00a β Install β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 3 β Rigger β 6/20/17 10:00a β 6/20/17 08:00p β Install β β ββββββ¬βββββββββ¬βββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 3 β Rigger β 6/21/17 07:00a β 6/21/17 04:00p β Travel Home β βββββββ©βββββββββ©βββββββββββββββββ©βββββββββββββββββ©ββββββββββββββββββββ
Typically, data consists of several roles over several days and often has multiple role instances on some (but not all) days.
One of the manipulations with the data that the code executes is to get this source data and reformat it into a pivot table so that the user can assign names later as soon as people are assigned. It is also the basis for various other individual work sheets and for calculating the number of flights / nights of a hotel, etc.
ββββββββ¦ββββββββββββ¦ββββββββββ¦ββββββββββ¦ββββββββββββββββββββββββββββββββββββββββ β NAME β ROLE β START β END β DESCRIPTION β β βββββββ¬ββββββββββββ¬ββββββββββ¬ββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ£ β β Rigger
I convert the source data from n-qty lines to nx lines from number 1 and add an instance counter to the role value if there are multiple instances. Currently, this is achieved by looping the data array several times and manipulating the data accordingly - psuedocode below
create 2-dimensional DataArray from source data Loop DataArray generate list of unique Roles Sum all Qty values Next Create 2-dimensional OutputArray size rows to match Sum of all Qty values in DataArray size cols to match DataArray cols //determine which UniqueRoles have multiple work instances For Each UniqueRole in DataArray Loop DataArray Count unique Start Dates for UniqueRole Sum Qty values for UniqueRole Next If Sum of UniqueRole Qtys > Count of UniqueRole unique Start Dates Then Add UniqueRole to MultpleInstanceList End If Next UniqueRole //copy data into new array, expand all n-qty rows into nx rows of 1 qty Loop DataArray Do While DataArray CurrentRow Qty Value > 1 Copy DataArray CurrentRow to OutputArray NewRow Overwrite Qty value in OutputArray = 1 Reduce DataArray CurrentRow Qty value by 1 Loop Copy DataArray CurrentRow to OutputArray NewRow Next //append count to Roles with multiple instances For Each UniqueRole in MultipleInstanceList Loop OutputArray generate list of unique Start Dates for current UniqueRole Next For Each StartDate in UniqueStartDates Loop OutputArray generate row index list for matching UniqueRole AND StartDate Next initialize counter k = 1 For Each Row in RowIndexList OutputArray(Row) Role value = Role value & " #" & k k = k + 1 Next Row Next StartDate Next UniqueRoleVaue
Then I create a pivot table from the extended array.
This works great for simple cases, however, when complex configurations exist, it can create inconsistent results when adding an instance number relative to the description value, for example ...
βββββββ¦βββββββββ¦ββββββββββββββββββ¦βββββββββββββββββ¦ββββββββββββββββββββ β QTY β ROLE β START β END β DESCRIPTION β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/15/17 08:00a β 6/15/17 04:00p β Travel to Prep β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/16/17 08:00a β 6/16/17 06:00p β Prep β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/17/17 08:00a β 6/17/17 07:00p β Prep β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 3 β Rigger β 6/18/17 06:00a β 6/18/18 05:00p β Travel to Install β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 3 β Rigger β 6/19/17 08:00a β 6/19/17 06:00p β Install β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 1 β Rigger β 6/20/17 07:00a β 6/20/17 04:00p β Travel Home β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 2 β Rigger β 6/20/17 08:00a β 6/20/17 06:00p β Install β β ββββββ¬βββββββββ¬ββββββββββββββββββ¬βββββββββββββββββ¬ββββββββββββββββββββ£ β 2 β Rigger β 6/21/17 07:00a β 6/21/17 04:00p β Travel Home β βββββββ©βββββββββ©ββββββββββββββββββ©βββββββββββββββββ©ββββββββββββββββββββ
... will be displayed ...
βββββββββββββ¦ββββββββββ¦ββββββββββ¦βββββββββββββββββββββββββββββββββββββββββββββ β ROLE β START β END β DESCRIPTION β β ββββββββββββ¬ββββββββββ¬ββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ£ β Rigger
All this operation is performed several times during normal use of the document, and if the data order is changed (which is possible), it can also create inconsistent results between operations.
I would prefer not to sort the original array as part of the operation, as it is an expensive process that adds a noticeable delay after the table hits 10 rows, even when using merge sort or quick sort.
I try to make this process as optimized as possible; many other outputs use this extended array, some of which effectively provide direct feedback, so the operation is performed every time the user enters data.
The list of possible descriptions that the user can select is predefined.
βββββββββββββββββββββββββ β Travel to Prep β β ββββββββββββββββββββββββ£ β Travel & Prep β β ββββββββββββββββββββββββ£ β Prep β β ββββββββββββββββββββββββ£ β Prep & Travel β β ββββββββββββββββββββββββ£ β Travel to Install β β ββββββββββββββββββββββββ£ β Travel & Install β β ββββββββββββββββββββββββ£ β Install β β ββββββββββββββββββββββββ£ β Travel to Show β β ββββββββββββββββββββββββ£ β Rehearsal β β ββββββββββββββββββββββββ£ β Show β β ββββββββββββββββββββββββ£ β Show & Dismantle β β ββββββββββββββββββββββββ£ β Travel to Dismantle β β ββββββββββββββββββββββββ£ β Dismantle β β ββββββββββββββββββββββββ£ β Travel Home β β ββββββββββββββββββββββββ£ β Travel to Site Survey β β ββββββββββββββββββββββββ£ β Site Survey β β ββββββββββββββββββββββββ£ β Dark Day β βββββββββββββββββββββββββ
I think this is an effectively oriented graph, all edges have a direction (most of them are one-sided), and some nodes can be closed. I built an adjacency matrix for the above list, as this is apparently the logical way to determine if the assignment order is valid.
Is there an effective way to ensure that all paths for a specific role are valid workarounds and what is the best way to assign role instance numbers if one or more paths are invalid?
Or is it possible to use a subset of description values ββat each traversal level during the extension operation to ensure that role instance numbers are correctly assigned?
Is there a certain area of ββgraph theory that I should look at? Are the graphics right? Is there an alternative approach that will work / be more effective?
Any advice / help would be greatly appreciated.
thanks