Click here to Skip to main content
15,075,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two different files, fileA contains employee data (ID and townCode) while file B contains field office data (OfficeID, Town, TownCode, officeCapacity) and a town can contain more than one office. i want to distribute these employees to the offices in the town against their names evenly

What I have tried:

I read the 2 files simulteanously and created another file to hold the last office it was distributed to. My challenge is that the distribution is not even and it picks only 2 offices for the distribution
VB
For Each line In File.ReadLines(src1)
           Dim STRDATA() As String = line.Split({","c})
           employeeID = STRDATA(0)
           EmpTownCode = STRDATA(1)

           For Each lines In File.ReadLines(src2)
               Dim STRDATA2() As String = lines.Split({","c})

               OfficeID = STRDATA2(0)
               StrTownName = STRDATA2(1)
               StrTownCode = STRDATA2(2)
               OfficeCapacity = STRDATA2(3)
               For Each last In File.ReadLines(src3)
                   lastCentre = last.Substring(0, 16)
               Next

               If StrRegTown = StrTownCode Then
                   If StrCentreRef = lastCentre.Last Then
                       Exit For
                   End If
                   FileOpen(intoutfilenum, outfilepath, OpenMode.Append)
                   WriteLine(intoutfilenum, EmployeeID, TownCode, OfficeID, OfficeCapacity)
                   FileClose(intoutfilenum)
                   FileOpen(intoutfilenum2, outfilepath2, OpenMode.Append)
                   WriteLine(intoutfilenum2, OfficeID)
                   FileClose(intoutfilenum2)
                   Exit For
               End If
Posted
Updated 22-Apr-21 18:07pm

1 solution

I think reading the two data files and attempting to solve this problem at the same time is not such a nice approach.

I would

1) read each file into a data structure - possibly array or 'list'
2) sketch out a distribution algorithm on paper. You don't indicate relative 'numbers' of employees vs offices - but I'd assume that for every town -> office, you want at least 1 employee, distributing up to OfficeCapacity employees q) what happens if all town -> offices are allocated OfficeCapacity employees ? do you assign them to another (nearest) town ?
3) translate the sketch algorithm from 2 into code - depending on how complex your rules are, you may need to change the data structures used and/or add back-tracking
   
Comments
ketura 23-Apr-21 0:43am
   
Thank you @Garth for the swift response; I have also tried reading the office file into an array-list but I ran into problems trying to do the assignment.
If all town -> offices are allocated employees, you start another round of shift. An employee must not be outside her preferred town

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900