District

Top  Previous  Next

Function District(method: integer; centerfile, customerfile, outputfile: string): integer;

 

This function solves the problem of assigning students to schools, where each school has a maximum capacity. The criteria for assigning students is to minimize the total cost (normally distance) for all students. The function can be used for other problems too and therefore schools are also referred to as centers, while the students are referred to as customers below.

 

Centerfile is the filename of a text-file, which contains the information for the centers. Include one line for each center with this space-delimited information: X-coordinate, Y-coordinate and capacity.

 

Customerfile is the filename of a text-file, which contains the information for the customers. Include one line for each customer with this space-delimited information: X-coordinate and Y-coordinate.

 

There can be any number of centers (>= 1) and customers (>= 1). If the total capacity of the centers is smaller than the number of customers, only some of the customers will be assigned to a center.

 

The outputfile is the name of a text-file with the results from the calculations. It looks like this:

 

ID Center Priority Cost

1 4 1  0.657

2 0 0  0.000

3 0 0  0.000

4 0 0  0.000

5 3 1  1.331

6 0 0  0.000

7 0 0  0.000

8 3 1  1.125

9 3 1  1.176

10 3 1  1.091

 

ID refers to the number of the customer in the customerfile (line number).

Center is the number of the center, which the customer has been assigned to. Here both customer 2, 3, 4, 6 and 7 have not been assigned.

Priority is 1, of the customer has been assigned to the nearest center, 2 if it was the 2nd nearest etc.

Cost is the actual cost of getting there.

 

The function returns 0, if no errors happened.

 

The Method parameter is not being used at the moment, but will later be used for adding more district optimization methods.

 

Possible error codes: -10 -32 -40 -41 -43

Versions: Pro

ActiveX / VCL / CLX component: RWcalc

 

 

This map shows an example of 6 schools and assignment of students. It can easily be seen, that school 1 has too little capacity since many of the nearest students has been assigned to other schools with sufficient capacity (both schools 2, 5 and 6):