[ / / / / / / / / / / / / / ] [ dir / asmr / clang / hikki / ita / strek / tijuana / vore / wai ][Options][ watchlist ]

/prog/ - Programming

Programming board
You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

[–]

4aade7 (2) No.4860>>4865 [Watch Thread][Show All Posts]

This is part of a program that works out the logistics for a company that delivers stuff using trucks. There are multiple trucks and each truck gets a route, each route contains loads. I get the loads from a SQL query, each row of the recordset specifies to which route this load (row contents) belongs. If two loads belong to the same route, they should both go on the same truck, so the routes have to be joined together. However each load has different amounts of pallets and different amounts of stops. These pallets and stops have to be added together.

Below is the code I am currently using, can any of you guys think of a way to improve the algorithm or know of a better algorithm altogether?

The current one works well enough if the query returns a decent amount of Loads, but I am worried about how it will perform if there are many Loads.


STLoad is structure
Route is string
Approx_Pallets is string
Stops is string
Gross is string
end

arrSTLoads is array of STLoad
// Records returned by a SQL query have been read into this ^ array of structure

Done is boolean = False

WHILE Done = False
FOR i=1 TO ArrayCount(arrSTLoads)
FOR j=1 TO ArrayCount(arrSTLoads)
IF i<>j THEN // Prevents adding a load to itself
IF arrSTLoads[i].Route = arrSTLoads[j].Route THEN // If both Loads are on the same route, they should be joined together

arrSTLoads[i].nApprox_Pallets = Val(arrSTLoads[i].Approx_Pallets) + Val(arrSTLoads[j].Approx_Pallets) // Pallets of both Routes added together
arrSTLoads[i].nStop = Val(arrSTLoads[i].Stops) + Val(arrSTLoads[j].Stops) // Amount of Stops the two Loads require added together

ArrayDelete(arrSTLoads,j) // Keep the first Load and remove the second from the array of Structure.
GOTO Slip // Array length and iterator location are no longer correct, break out of both for loops
END
END
END
END

Slip:
Done = True // Used to determine wether there are any Loads left that still need to be joined.

FOR i=1 TO ArrayCount(arrSTLoads)
FOR j=1 TO ArrayCount(arrSTLoads)
IF i<>j THEN
IF arrSTLoads[i].Route = arrSTLoads[j].Route THEN
Done = False // Loads that have to be joined found, while loop has to go for another round
GOTO Slip2 // Loads have been found that still have to be joined, break out of both for loops
END
END
END
END
Slip2:
END

4aade7 (2) No.4865

>>4860 (OP)

Thanks to an Anon over at Lainchan, I've managed to make some improvements, for the sake of interest here is how it looks now.


STLoad is structure
Route is string
Approx_Pallets is string
Stops is string
end

arrSTLoads is array of STLoad
// Records returned by a SQL query have been read into this ^ array of structure

ArraySort(arrSTLoads,AsMember,"Route;")

Done is boolean = False

WHILE Done = False
FOR i=1 TO ArrayCount(arrSTLoads)
FOR j=1 TO ArrayCount(arrSTLoads)
IF i<>j THEN // Prevents adding a load to itself
IF arrSTLoads[i].Route = arrSTLoads[j].Route THEN // If both Loads are on the same route, they should be joined together

arrSTLoads[i].nApprox_Pallets = Val(arrSTLoads[i].Approx_Pallets) + Val(arrSTLoads[j].Approx_Pallets) // Pallets of both Routes added together
arrSTLoads[i].nStop = Val(arrSTLoads[i].Stops) + Val(arrSTLoads[j].Stops) // Amount of Stops the two Loads require added together

ArrayDelete(arrSTLoads,j) // Keep the first Load and remove the second from the array of Structure.

CONTINUE(3)
END
END
END
END
BREAK
END




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
1 replies | 0 images | 1 UIDs | Page ?
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / asmr / clang / hikki / ita / strek / tijuana / vore / wai ][ watchlist ]