Initial commit. Refactored file input code.

This commit is contained in:
Rory Healy 2021-09-08 21:48:00 +10:00
commit c538ba2eb4
30 changed files with 1842 additions and 0 deletions

35
Makefile Normal file
View file

@ -0,0 +1,35 @@
# Link command:
#voronoi1: common.o dcel.o voronoi.o main.o
# gcc -Wall -Wextra -Werror -pedantic -g -o voronoi1 main.o voronoi.o dcel.o common.o
# Compilation commands:
#common.o: common.c
# gcc -Wall -Wextra -Werror -pedantic -g -o common.o common.c -c
#
#dcel.o: dcel.c
# gcc -Wall -Wextra -Werror -pedantic -g -o dcel.o dcel.c -c
#
#voronoi.o: voronoi.c
# gcc -Wall -Wextra -Werror -pedantic -g -o voronoi.o voronoi.c -c
#
#main.o: main.c
# gcc -Wall -Wextra -Werror -pedantic -g -o main.o main.c -c
# Link command:
voronoi2: common.o dcel.o voronoi.o input.o main.o
gcc -Wall -Wextra -Werror -pedantic -g -o voronoi2 main.o input.o voronoi.o dcel.o common.o
common.o: common.c
gcc -Wall -Wextra -Werror -pedantic -g -o common.o common.c -c
dcel.o: dcel.c
gcc -Wall -Wextra -Werror -pedantic -g -o dcel.o dcel.c -c
voronoi.o: voronoi.c
gcc -Wall -Wextra -Werror -pedantic -g -o voronoi.o voronoi.c -c
main.o: main.c
gcc -Wall -Wextra -Werror -pedantic -g -o main.o main.c -c
input.o: input.c
gcc -Wall -Wextra -Werror -pedantic -g -o input.o input.c -c

21
common.c Normal file
View file

@ -0,0 +1,21 @@
/* common.c
*
* Created by Rory Healy (healyr@student.unimelb.edu.au)
* Created on 25th August 2021
* Last modified 8th September 2021
*
* Contains functions for general use throughout other files.
*
*/
#ifndef COMMON_HEADER
#include "common.h"
#endif
/* Checks if a given pointer is null. Used for malloc() and realloc(). */
void checkNullPointer(void *ptr) {
if (!ptr) {
fputs("Error: Cannot allocate memory.\n", stderr);
exit(EXIT_FAILURE);
}
}

20
common.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef STDIO_HEADER
#define STDIO_HEADER
#include <stdio.h>
#endif
#ifndef STDLIB_HEADER
#define STDLIB_HEADER
#include <stdlib.h>
#endif
#ifndef COMMON_HEADER
#define COMMON_HEADER
void checkNullPointer(void *ptr);
#endif

BIN
common.o Normal file

Binary file not shown.

2
dataset_1.csv Normal file
View file

@ -0,0 +1,2 @@
Watchtower ID,Postcode,Population Served,Watchtower Point of Contact Name,x,y
WT3765SHSPB,3765,3380,Eilene Horner,145.36201379669092,-37.81894302945288
1 Watchtower ID Postcode Population Served Watchtower Point of Contact Name x y
2 WT3765SHSPB 3765 3380 Eilene Horner 145.36201379669092 -37.81894302945288

11
dataset_10.csv Normal file
View file

@ -0,0 +1,11 @@
Watchtower ID,Postcode,Population Served,Watchtower Point of Contact Name,x,y
WT3106HTUYW,3106,2374,David Bryan,145.14493956217032,-37.74550312585378
WT3151ANFQX,3151,3424,Daniel Davis,145.16632131582105,-37.84908719684687
WT3953SGAEI,3953,1571,Ofelia Kadlec,145.77800174296402,-38.55984015166651
WT3765SHSPB,3765,3380,Eilene Horner,145.36201379669092,-37.81894302945288
WT3227LRSVA,3227,4819,Joan Cox,144.38837299987338,-38.22664848840161
WT3370XRAHI,3370,356,Tammy Compton,143.76050524940354,-37.17889378247109
WT3525YPKBW,3525,433,Denise Roberts,143.32090727836928,-36.14524876420747
WT3701KWYIQ,3701,269,Martha Moore,147.39302957919313,-36.254894160169314
WT3779NULEK,3779,197,Aida Kuhnle,146.11080887018696,-37.67951918079387
WT3530RJWDT,3530,63,Troy Clark,143.0834668479817,-35.79299394885817
1 Watchtower ID Postcode Population Served Watchtower Point of Contact Name x y
2 WT3106HTUYW 3106 2374 David Bryan 145.14493956217032 -37.74550312585378
3 WT3151ANFQX 3151 3424 Daniel Davis 145.16632131582105 -37.84908719684687
4 WT3953SGAEI 3953 1571 Ofelia Kadlec 145.77800174296402 -38.55984015166651
5 WT3765SHSPB 3765 3380 Eilene Horner 145.36201379669092 -37.81894302945288
6 WT3227LRSVA 3227 4819 Joan Cox 144.38837299987338 -38.22664848840161
7 WT3370XRAHI 3370 356 Tammy Compton 143.76050524940354 -37.17889378247109
8 WT3525YPKBW 3525 433 Denise Roberts 143.32090727836928 -36.14524876420747
9 WT3701KWYIQ 3701 269 Martha Moore 147.39302957919313 -36.254894160169314
10 WT3779NULEK 3779 197 Aida Kuhnle 146.11080887018696 -37.67951918079387
11 WT3530RJWDT 3530 63 Troy Clark 143.0834668479817 -35.79299394885817

101
dataset_100.csv Normal file
View file

@ -0,0 +1,101 @@
Watchtower ID,Postcode,Population Served,Watchtower Point of Contact Name,x,y
WT3023QBQJF,3023,12794,Sandra Jaynes,144.7116868675065,-37.79835253004884
WT3037YAKEI,3037,25577,Paul Watson,144.7404381965215,-37.71057606210163
WT3810RRMDP,3810,47894,Shirl Bays,145.54377380709113,-38.11642115246884
WT3550ANADF,3550,10084,Virginia Lumpkins,144.25225555806287,-36.7583657822827
WT3754SXJZI,3754,6292,Henriette Mitchell,145.1619799395555,-37.61057382984485
WT3754WSOKP,3754,6292,James Lopez,145.11378037030943,-37.60927638542337
WT3046ADKBS,3046,8515,Morris Pring,144.94317380188164,-37.71659755462475
WT3178BQAJG,3178,5612,Malka Smith,145.26959423333145,-37.918875236595035
WT3130PLSQY,3130,8043,Jose Hayes,145.13764760079675,-37.828083908584475
WT3032PWVMB,3032,7362,William Mackiewicz,144.87559681642185,-37.79083145310446
WT3173JKIEY,3173,5157,Teddy Mccauley,145.18948448769126,-37.992844271467284
WT3122GVRSM,3122,11755,William Bell,145.0366394627393,-37.810997917513916
WT3171BGAEJ,3171,7238,Lila Levy,145.1337946019459,-37.92898751855743
WT3128AQDRS,3128,6609,Sarah Kauffman,145.1295813912443,-37.82078823368618
WT3219MZCMM,3219,4928,Charlie Gerber,144.37942394090373,-38.19362930153523
WT3170XJVWP,3170,9684,Lucy Lahay,145.17553159514887,-37.936150181976984
WT3031DMFGC,3031,6177,Caroline Luckenbach,144.90707048527796,-37.78767901585732
WT3015PKLER,3015,8736,Bill Kilbane,144.8979183219914,-37.82580808335247
WT3106WQFPR,3106,2374,Mary Bass,145.14274097499288,-37.731835101044354
WT3106HTUYW,3106,2374,David Bryan,145.14493956217032,-37.74550312585378
WT3352KHBBN,3352,15996,Richard Askew,143.60419898610786,-37.722432808576656
WT3079QORWG,3079,5329,Jerry Somogyi,145.05361972090736,-37.76092644646485
WT3850WPPZJ,3850,14779,Scott Buggie,146.99670975934802,-38.11120375121315
WT3400BOZRI,3400,14543,Tom Davis,142.2056868163526,-36.700923449995635
WT3123YZTIF,3123,7160,Paul Earwood,145.05955004240124,-37.82771644759941
WT3224OGJJN,3224,1773,Shirley Hall,144.42849521054393,-38.218027859101916
WT3137PJCVG,3137,1541,Yolanda Stern,145.32887887734955,-37.830025027117365
WT3305NMFYC,3305,3204,Larry Witter,141.29643421841453,-38.11167114301085
WT3305KWOFD,3305,3204,Judith Figueroa,141.25644777166127,-38.24079323443777
WT3025UXSIE,3025,2430,Willie Laigo,144.79429337101448,-37.82881778367748
WT3437KHBPL,3437,3479,Charlotte Green,144.59696365066134,-37.48113208398435
WT3151ANFQX,3151,3424,Daniel Davis,145.16632131582105,-37.84908719684687
WT3019ASCJP,3019,3065,Charlotte Coutermarsh,144.85492421197495,-37.772589492919515
WT3019JIKGX,3019,3065,Vincent January,144.85730316799982,-37.7718018219131
WT3764MKCUE,3764,4582,Alejandrina Salazar,144.970506104261,-37.15854276662507
WT3730UTUPX,3730,2944,Curtis Johnson,145.8390200963087,-36.01276678240247
WT3054SQEQA,3054,8428,Eugene Salano,144.95861592679725,-37.783412869711185
WT3620DPAMB,3620,4120,Ben Oneil,144.96824098896346,-36.398921729744224
WT3804OQOOF,3804,2023,Jackie Smith,145.35298253700518,-37.98426462189473
WT3909HFRJQ,3909,2633,Maria Rhodus,147.90601975805444,-37.764598529015366
WT3953SGAEI,3953,1571,Ofelia Kadlec,145.77800174296402,-38.55984015166651
WT3953NPQQN,3953,1571,Peter Willer,146.04193592469497,-38.44633595871089
WT3765SHSPB,3765,3380,Eilene Horner,145.36201379669092,-37.81894302945288
WT3027FZKQC,3027,3323,Angelo Hard,144.73167189283603,-37.85646049026309
WT3996ZMYGL,3996,1846,Jennifer Adkins,145.7771574897382,-38.67107249698782
WT3984UBSFJ,3984,1041,Ned Johnson,145.61381415852048,-38.3660140349184
WT3227LRSVA,3227,4819,Joan Cox,144.38837299987338,-38.22664848840161
WT3950WWFHI,3950,2400,Donald Neil,145.789697571232,-38.44829776894874
WT3842LLUAZ,3842,2391,Justin Butcher,146.43738290720543,-38.33409319136186
WT3225ZWRKT,3225,1352,Sierra Zelaya,144.63248453729392,-38.273920927385454
WT3797JXEYZ,3797,1738,Wade Seay,145.59525777895735,-37.85187937890587
WT3980CXZJX,3980,1675,Marianne Gulledge,145.38407991603268,-38.234540388656654
WT3862WPONG,3862,1578,Anthony Dawkins,147.33271058732282,-37.491238739170896
WT3202IDOPR,3202,1453,Shannon Bello,145.07561474247163,-37.947828524869706
WT3304LTOER,3304,681,James Broadway,141.91304296053238,-38.08286392590754
WT3478NOSNX,3478,614,Mary Wooster,143.190083774406,-36.70864776402552
WT3373ZJBZG,3373,573,Helen Hu,143.40004730403342,-37.327257624451846
WT3373FDEUM,3373,573,Phyllis Hegyi,143.19424925274458,-37.38771716562931
WT3370XRAHI,3370,356,Tammy Compton,143.76050524940354,-37.17889378247109
WT3673HXZDV,3673,346,June Matteson,145.99560167654946,-36.51826050506983
WT3943FFEHH,3943,398,Floyd Mcfaul,144.7219219690698,-38.32665967904324
WT3937YBAGH,3937,762,Tyesha Evans,145.0385876851752,-38.37262744294901
WT3786QKGRU,3786,506,Joe Pulaski,145.33261178176102,-37.876147897332174
WT3321FSNXX,3321,759,James Mcintosh,144.00220559674338,-38.10453080180178
WT3525YPKBW,3525,433,Denise Roberts,143.32090727836928,-36.14524876420747
WT3231VKTTU,3231,418,Karl Evans,143.99174248566703,-38.47241568127852
WT3231YSKOO,3231,418,Leontine Mcghee,144.07128861030645,-38.416049306559025
WT3766LYICC,3766,619,Gary Evans,145.3953639008541,-37.81880414343826
WT3381FUDIA,3381,151,Penny Carrier,142.7602629758581,-37.02897861269415
WT3232GSLYH,3232,1114,Joshua Sickafoose,143.96111969797116,-38.544885004427805
WT3933UXXXP,3933,549,Shaun Guffey,145.11706009902144,-38.26228415412558
WT3701KWYIQ,3701,269,Martha Moore,147.39302957919313,-36.254894160169314
WT3701TPSEH,3701,269,Grant Kennedy,147.41241338695838,-36.74234154193107
WT3312BCEJQ,3312,1031,Alexandra Ratzlaff,141.38649875710092,-37.85213620536482
WT3332VSYVL,3332,338,Charles Koons,144.08742265383532,-37.906318691909874
WT3623CXKIC,3623,224,Rebecca Lara,144.90863570166192,-36.44103547317975
WT3289ZSWDS,3289,378,Kim Hall,142.1760506248015,-37.83343114690931
WT3728YZARW,3728,318,Heather Cummings,145.8168813215635,-36.115027477064245
WT3633WGRXB,3633,201,John Miller,145.48023893751045,-36.2875408553956
WT3633UVHAO,3633,201,Michael Price,145.51505172180683,-36.31027112244356
WT3637KIERO,3637,198,Robert Dow,145.25553090556156,-36.0980796504903
WT3063WZIQE,3063,114,James Miller,144.81061694155076,-37.553501843305575
WT3334GGKOS,3334,141,Elizabet Benson,144.1621690362788,-37.67891238372265
WT3251FUJSG,3251,522,Lisa Voegele,143.5797389397756,-38.1623931117428
WT3649NJHAF,3649,86,Catherine Ortiz,145.70444412227315,-36.12591041370753
WT3287NEKVB,3287,216,Joel Simmons,142.26305043381535,-37.983480961999916
WT3407PYOAR,3407,420,Gale Martin,141.83324586447986,-37.2859635851256
WT3779NULEK,3779,197,Aida Kuhnle,146.11080887018696,-37.67951918079387
WT3719TVVJM,3719,122,Brent Bautista,145.6864773045679,-37.03188286944955
WT3719HLABD,3719,122,Alfred Too,145.52985920519603,-36.964844896202216
WT3573DPVGU,3573,111,Wiley Palmer,144.15009214850954,-36.12318035418112
WT3254RXAVL,3254,310,Amy Pugh,143.54387071993327,-38.308515316326016
WT3832NHOOV,3832,247,Bryan Warren,146.0154412945935,-37.93424551655733
WT3238BOTYW,3238,72,Bernard Jackson,143.567776369521,-38.625836774939955
WT3238MCUPV,3238,72,Nellie Banks,143.56196753560545,-38.82942446565583
WT3375LAJLR,3375,104,Emma Boatwright,143.2980117885972,-37.372200644973155
WT3530RJWDT,3530,63,Troy Clark,143.0834668479817,-35.79299394885817
WT3596HBEUF,3596,47,Jose Robertson,143.15095468769667,-35.190473662123345
WT3293SQKBY,3293,100,Shawn Clark,142.64808203542347,-37.82556647618436
WT3887NLNSJ,3887,342,Lorene Anderson,147.96080438424718,-37.76269836557282
1 Watchtower ID Postcode Population Served Watchtower Point of Contact Name x y
2 WT3023QBQJF 3023 12794 Sandra Jaynes 144.7116868675065 -37.79835253004884
3 WT3037YAKEI 3037 25577 Paul Watson 144.7404381965215 -37.71057606210163
4 WT3810RRMDP 3810 47894 Shirl Bays 145.54377380709113 -38.11642115246884
5 WT3550ANADF 3550 10084 Virginia Lumpkins 144.25225555806287 -36.7583657822827
6 WT3754SXJZI 3754 6292 Henriette Mitchell 145.1619799395555 -37.61057382984485
7 WT3754WSOKP 3754 6292 James Lopez 145.11378037030943 -37.60927638542337
8 WT3046ADKBS 3046 8515 Morris Pring 144.94317380188164 -37.71659755462475
9 WT3178BQAJG 3178 5612 Malka Smith 145.26959423333145 -37.918875236595035
10 WT3130PLSQY 3130 8043 Jose Hayes 145.13764760079675 -37.828083908584475
11 WT3032PWVMB 3032 7362 William Mackiewicz 144.87559681642185 -37.79083145310446
12 WT3173JKIEY 3173 5157 Teddy Mccauley 145.18948448769126 -37.992844271467284
13 WT3122GVRSM 3122 11755 William Bell 145.0366394627393 -37.810997917513916
14 WT3171BGAEJ 3171 7238 Lila Levy 145.1337946019459 -37.92898751855743
15 WT3128AQDRS 3128 6609 Sarah Kauffman 145.1295813912443 -37.82078823368618
16 WT3219MZCMM 3219 4928 Charlie Gerber 144.37942394090373 -38.19362930153523
17 WT3170XJVWP 3170 9684 Lucy Lahay 145.17553159514887 -37.936150181976984
18 WT3031DMFGC 3031 6177 Caroline Luckenbach 144.90707048527796 -37.78767901585732
19 WT3015PKLER 3015 8736 Bill Kilbane 144.8979183219914 -37.82580808335247
20 WT3106WQFPR 3106 2374 Mary Bass 145.14274097499288 -37.731835101044354
21 WT3106HTUYW 3106 2374 David Bryan 145.14493956217032 -37.74550312585378
22 WT3352KHBBN 3352 15996 Richard Askew 143.60419898610786 -37.722432808576656
23 WT3079QORWG 3079 5329 Jerry Somogyi 145.05361972090736 -37.76092644646485
24 WT3850WPPZJ 3850 14779 Scott Buggie 146.99670975934802 -38.11120375121315
25 WT3400BOZRI 3400 14543 Tom Davis 142.2056868163526 -36.700923449995635
26 WT3123YZTIF 3123 7160 Paul Earwood 145.05955004240124 -37.82771644759941
27 WT3224OGJJN 3224 1773 Shirley Hall 144.42849521054393 -38.218027859101916
28 WT3137PJCVG 3137 1541 Yolanda Stern 145.32887887734955 -37.830025027117365
29 WT3305NMFYC 3305 3204 Larry Witter 141.29643421841453 -38.11167114301085
30 WT3305KWOFD 3305 3204 Judith Figueroa 141.25644777166127 -38.24079323443777
31 WT3025UXSIE 3025 2430 Willie Laigo 144.79429337101448 -37.82881778367748
32 WT3437KHBPL 3437 3479 Charlotte Green 144.59696365066134 -37.48113208398435
33 WT3151ANFQX 3151 3424 Daniel Davis 145.16632131582105 -37.84908719684687
34 WT3019ASCJP 3019 3065 Charlotte Coutermarsh 144.85492421197495 -37.772589492919515
35 WT3019JIKGX 3019 3065 Vincent January 144.85730316799982 -37.7718018219131
36 WT3764MKCUE 3764 4582 Alejandrina Salazar 144.970506104261 -37.15854276662507
37 WT3730UTUPX 3730 2944 Curtis Johnson 145.8390200963087 -36.01276678240247
38 WT3054SQEQA 3054 8428 Eugene Salano 144.95861592679725 -37.783412869711185
39 WT3620DPAMB 3620 4120 Ben Oneil 144.96824098896346 -36.398921729744224
40 WT3804OQOOF 3804 2023 Jackie Smith 145.35298253700518 -37.98426462189473
41 WT3909HFRJQ 3909 2633 Maria Rhodus 147.90601975805444 -37.764598529015366
42 WT3953SGAEI 3953 1571 Ofelia Kadlec 145.77800174296402 -38.55984015166651
43 WT3953NPQQN 3953 1571 Peter Willer 146.04193592469497 -38.44633595871089
44 WT3765SHSPB 3765 3380 Eilene Horner 145.36201379669092 -37.81894302945288
45 WT3027FZKQC 3027 3323 Angelo Hard 144.73167189283603 -37.85646049026309
46 WT3996ZMYGL 3996 1846 Jennifer Adkins 145.7771574897382 -38.67107249698782
47 WT3984UBSFJ 3984 1041 Ned Johnson 145.61381415852048 -38.3660140349184
48 WT3227LRSVA 3227 4819 Joan Cox 144.38837299987338 -38.22664848840161
49 WT3950WWFHI 3950 2400 Donald Neil 145.789697571232 -38.44829776894874
50 WT3842LLUAZ 3842 2391 Justin Butcher 146.43738290720543 -38.33409319136186
51 WT3225ZWRKT 3225 1352 Sierra Zelaya 144.63248453729392 -38.273920927385454
52 WT3797JXEYZ 3797 1738 Wade Seay 145.59525777895735 -37.85187937890587
53 WT3980CXZJX 3980 1675 Marianne Gulledge 145.38407991603268 -38.234540388656654
54 WT3862WPONG 3862 1578 Anthony Dawkins 147.33271058732282 -37.491238739170896
55 WT3202IDOPR 3202 1453 Shannon Bello 145.07561474247163 -37.947828524869706
56 WT3304LTOER 3304 681 James Broadway 141.91304296053238 -38.08286392590754
57 WT3478NOSNX 3478 614 Mary Wooster 143.190083774406 -36.70864776402552
58 WT3373ZJBZG 3373 573 Helen Hu 143.40004730403342 -37.327257624451846
59 WT3373FDEUM 3373 573 Phyllis Hegyi 143.19424925274458 -37.38771716562931
60 WT3370XRAHI 3370 356 Tammy Compton 143.76050524940354 -37.17889378247109
61 WT3673HXZDV 3673 346 June Matteson 145.99560167654946 -36.51826050506983
62 WT3943FFEHH 3943 398 Floyd Mcfaul 144.7219219690698 -38.32665967904324
63 WT3937YBAGH 3937 762 Tyesha Evans 145.0385876851752 -38.37262744294901
64 WT3786QKGRU 3786 506 Joe Pulaski 145.33261178176102 -37.876147897332174
65 WT3321FSNXX 3321 759 James Mcintosh 144.00220559674338 -38.10453080180178
66 WT3525YPKBW 3525 433 Denise Roberts 143.32090727836928 -36.14524876420747
67 WT3231VKTTU 3231 418 Karl Evans 143.99174248566703 -38.47241568127852
68 WT3231YSKOO 3231 418 Leontine Mcghee 144.07128861030645 -38.416049306559025
69 WT3766LYICC 3766 619 Gary Evans 145.3953639008541 -37.81880414343826
70 WT3381FUDIA 3381 151 Penny Carrier 142.7602629758581 -37.02897861269415
71 WT3232GSLYH 3232 1114 Joshua Sickafoose 143.96111969797116 -38.544885004427805
72 WT3933UXXXP 3933 549 Shaun Guffey 145.11706009902144 -38.26228415412558
73 WT3701KWYIQ 3701 269 Martha Moore 147.39302957919313 -36.254894160169314
74 WT3701TPSEH 3701 269 Grant Kennedy 147.41241338695838 -36.74234154193107
75 WT3312BCEJQ 3312 1031 Alexandra Ratzlaff 141.38649875710092 -37.85213620536482
76 WT3332VSYVL 3332 338 Charles Koons 144.08742265383532 -37.906318691909874
77 WT3623CXKIC 3623 224 Rebecca Lara 144.90863570166192 -36.44103547317975
78 WT3289ZSWDS 3289 378 Kim Hall 142.1760506248015 -37.83343114690931
79 WT3728YZARW 3728 318 Heather Cummings 145.8168813215635 -36.115027477064245
80 WT3633WGRXB 3633 201 John Miller 145.48023893751045 -36.2875408553956
81 WT3633UVHAO 3633 201 Michael Price 145.51505172180683 -36.31027112244356
82 WT3637KIERO 3637 198 Robert Dow 145.25553090556156 -36.0980796504903
83 WT3063WZIQE 3063 114 James Miller 144.81061694155076 -37.553501843305575
84 WT3334GGKOS 3334 141 Elizabet Benson 144.1621690362788 -37.67891238372265
85 WT3251FUJSG 3251 522 Lisa Voegele 143.5797389397756 -38.1623931117428
86 WT3649NJHAF 3649 86 Catherine Ortiz 145.70444412227315 -36.12591041370753
87 WT3287NEKVB 3287 216 Joel Simmons 142.26305043381535 -37.983480961999916
88 WT3407PYOAR 3407 420 Gale Martin 141.83324586447986 -37.2859635851256
89 WT3779NULEK 3779 197 Aida Kuhnle 146.11080887018696 -37.67951918079387
90 WT3719TVVJM 3719 122 Brent Bautista 145.6864773045679 -37.03188286944955
91 WT3719HLABD 3719 122 Alfred Too 145.52985920519603 -36.964844896202216
92 WT3573DPVGU 3573 111 Wiley Palmer 144.15009214850954 -36.12318035418112
93 WT3254RXAVL 3254 310 Amy Pugh 143.54387071993327 -38.308515316326016
94 WT3832NHOOV 3832 247 Bryan Warren 146.0154412945935 -37.93424551655733
95 WT3238BOTYW 3238 72 Bernard Jackson 143.567776369521 -38.625836774939955
96 WT3238MCUPV 3238 72 Nellie Banks 143.56196753560545 -38.82942446565583
97 WT3375LAJLR 3375 104 Emma Boatwright 143.2980117885972 -37.372200644973155
98 WT3530RJWDT 3530 63 Troy Clark 143.0834668479817 -35.79299394885817
99 WT3596HBEUF 3596 47 Jose Robertson 143.15095468769667 -35.190473662123345
100 WT3293SQKBY 3293 100 Shawn Clark 142.64808203542347 -37.82556647618436
101 WT3887NLNSJ 3887 342 Lorene Anderson 147.96080438424718 -37.76269836557282

3
dataset_2.csv Normal file
View file

@ -0,0 +1,3 @@
Watchtower ID,Postcode,Population Served,Watchtower Point of Contact Name,x,y
WT3953SGAEI,3953,1571,Ofelia Kadlec,145.77800174296402,-38.55984015166651
WT3765SHSPB,3765,3380,Eilene Horner,145.36201379669092,-37.81894302945288
1 Watchtower ID Postcode Population Served Watchtower Point of Contact Name x y
2 WT3953SGAEI 3953 1571 Ofelia Kadlec 145.77800174296402 -38.55984015166651
3 WT3765SHSPB 3765 3380 Eilene Horner 145.36201379669092 -37.81894302945288

4
dataset_3.csv Normal file
View file

@ -0,0 +1,4 @@
Watchtower ID,Postcode,Population Served,Watchtower Point of Contact Name,x,y
WT3953SGAEI,3953,1571,Ofelia Kadlec,145.77800174296402,-38.55984015166651
WT3765SHSPB,3765,3380,Eilene Horner,145.36201379669092,-37.81894302945288
WT3530RJWDT,3530,63,Troy Clark,143.0834668479817,-35.79299394885817
1 Watchtower ID Postcode Population Served Watchtower Point of Contact Name x y
2 WT3953SGAEI 3953 1571 Ofelia Kadlec 145.77800174296402 -38.55984015166651
3 WT3765SHSPB 3765 3380 Eilene Horner 145.36201379669092 -37.81894302945288
4 WT3530RJWDT 3530 63 Troy Clark 143.0834668479817 -35.79299394885817

5
dataset_4.csv Normal file
View file

@ -0,0 +1,5 @@
Watchtower ID,Postcode,Population Served,Watchtower Point of Contact Name,x,y
WT3953SGAEI,3953,1571,Ofelia Kadlec,145.77800174296402,-38.55984015166651
WT3765SHSPB,3765,3380,Eilene Horner,145.36201379669092,-37.81894302945288
WT3530RJWDT,3530,63,Troy Clark,143.0834668479817,-35.79299394885817
WT3701KWYIQ,3701,269,Martha Moore,147.39302957919313,-36.254894160169314
1 Watchtower ID Postcode Population Served Watchtower Point of Contact Name x y
2 WT3953SGAEI 3953 1571 Ofelia Kadlec 145.77800174296402 -38.55984015166651
3 WT3765SHSPB 3765 3380 Eilene Horner 145.36201379669092 -37.81894302945288
4 WT3530RJWDT 3530 63 Troy Clark 143.0834668479817 -35.79299394885817
5 WT3701KWYIQ 3701 269 Martha Moore 147.39302957919313 -36.254894160169314

1081
dataset_full.csv Normal file

File diff suppressed because it is too large Load diff

68
dcel.c Normal file
View file

@ -0,0 +1,68 @@
/* dcel.c
*
* Created by Rory Healy (healyr@student.unimelb.edu.au)
* Created on 25th August 2021
* Last modified 25th August 2021
*
* Contains functions for the DCEL data structure, including creating,
* splitting an edge, and identifying towers in faces.
*
*/
#ifndef DCEL_HEADER
#include "dcel.h"
#endif
#ifndef COMMON_HEADER
#include "common.h"
#endif
struct halfEdge {
halfEdge_t *previous;
halfEdge_t *next;
halfEdge_t *twin;
int face;
int edge;
};
struct vertex {
double x;
double y;
};
struct edge {
halfEdge_t halfEdge;
};
struct face {
halfEdge_t start;
};
/* Reads the polygon file and stores the information in the vertices array. */
vertex_t **readPolygon(vertex_t **vertices, FILE *polygonFile, int *numVertices) {
double currentX, currentY;
int maxSizeVertices = 1;
while ((fscanf(polygonFile, "%lf %lf", &currentX, &currentY)) != EOF) {
/* Check if there enough space in the towers array */
if (*numVertices == maxSizeVertices) {
maxSizeVertices *= 2;
vertex_t **temp = realloc(vertices, maxSizeVertices * sizeof(*vertices));
checkNullPointer(temp);
vertices = temp;
}
/* The current vertex being filled in with information */
vertices[*numVertices] = malloc(sizeof(*vertices[*numVertices]));
vertices[*numVertices]->x = currentX;
vertices[*numVertices]->y = currentY;
*numVertices += 1;
}
return vertices;
}
void freeVertices(vertex_t **vertices, int numVertices) {
for (int i = 0; i < numVertices; i++) {
free(vertices[i]);
}
free(vertices);
}

20
dcel.h Normal file
View file

@ -0,0 +1,20 @@
#ifndef STDIO_HEADER
#define STDIO_HEADER
#include <stdio.h>
#endif
#ifndef DCEL_HEADER
#define DCEL_HEADER
typedef struct halfEdge halfEdge_t;
typedef struct vertex vertex_t;
typedef struct edge edge_t;
typedef struct face face_t;
vertex_t **readPolygon(vertex_t **vertices, FILE *polygonFile, \
int *numVertices);
void freeVertices(vertex_t **vertices, int numVertices);
#endif

BIN
dcel.o Normal file

Binary file not shown.

102
input.c Normal file
View file

@ -0,0 +1,102 @@
/* input.c
*
* Created by Rory Healy (healyr@student.unimelb.edu.au)
* Created on 8th September 2021
* Last modified 8th September 2021
*
* Contains functions for ensuring correct input arguments are given for
* each stage of the voronoi2 program.
*
*/
#ifndef INPUT_HEADER
#include "input.h"
#endif
#define STAGE_1_ARG_COUNT 4
#define STAGE_2_ARG_COUNT 5
#define STAGE_3_ARG_COUNT 5
#define STAGE_4_ARG_COUNT 5
#define OPEN_FILE_ERROR "Error: Unable to open file %s\n"
enum stages getStage(char *stage) {
if (strcmp(stage, "1") == 0){
return STAGE_1;
} else if (strcmp(stage, "2") == 0){
return STAGE_2;
} else if (strcmp(stage, "3") == 0){
return STAGE_3;
} else if (strcmp(stage, "4") == 0){
return STAGE_4;
} else {
return STAGE_ERROR;
}
}
void printArgError(enum stages stage, char *errorMessage) {
fprintf(stderr, "Error: %s\n\n", errorMessage);
/* Stage 1 - Print bisector equations */
if (stage == STAGE_ERROR || stage == STAGE_1) {
fputs("./voronoi2 1 pointsFile outputFile\n"
"\tTo output the bisectors for the given pointsFile to the \n"
"\tgiven outputFile.\n\n", stderr);
}
/* Stage 2 - Print intersections between bisectors and polygon */
if (stage == STAGE_ERROR || stage == STAGE_2) {
fputs("./voronoi2 2 pointsFile polygonFile outputFile\n"
"\tTo output the intersections the given bisectors make with \n"
"\tthe polygon to the given outputFile.\n\n", stderr);
}
/* Stage 3: Print diameter of each face, constructing using
* incremental method
*/
if (stage == STAGE_ERROR || stage == STAGE_3) {
fputs("./voronoi2 3 dataFile polygonFile outputFile\n"
"\tTo generate the initial polygon in polygonFile, layout the \n"
"\twatchtower points in the dataFile on the polygon, generate \n"
"\the voronoi diagram, adding or modifying the polydon so that \n"
"\ta voronoi diagram is constructed, seperating all points \n"
"\tinto their own cell with all tpoints in the cell being \n"
"\tclosest to the watchtower in the cell. The watchtower data \n"
"\tand its diameter is output to the outputFile.\n\n", stderr);
}
/* Stage 4 - Sort by diameter */
if (stage == STAGE_ERROR || stage == STAGE_4) {
fputs("./voronoi2 4 dataFile polygonFile outputFile\n"
"\tSame as stage 3, but output watchtowers are in order of \n"
"\tdiameter, smallest to largest.\n\n", stderr);
}
exit(EXIT_FAILURE);
}
int getExpectedArgs(enum stages stage) {
switch(stage){
case STAGE_1:
return STAGE_1_ARG_COUNT;
case STAGE_2:
return STAGE_2_ARG_COUNT;
case STAGE_3:
return STAGE_3_ARG_COUNT;
case STAGE_4:
return STAGE_4_ARG_COUNT;
case STAGE_ERROR:
default:
printArgError(stage, "Invalid stage number.");
exit(EXIT_FAILURE);
}
return -1;
}
FILE *safeFileOpen(FILE **f, char *fileName, char *mode) {
*f = fopen(fileName, mode);
if (*f == NULL) {
fputs(OPEN_FILE_ERROR, stderr);
exit(EXIT_FAILURE);
}
return *f;
}

48
input.h Normal file
View file

@ -0,0 +1,48 @@
#ifndef STDIO_HEADER
#define STDIO_HEADER
#include <stdio.h>
#endif
#ifndef STDLIB_HEADER
#define STDLIB_HEADER
#include <stdlib.h>
#endif
#ifndef STRING_HEADER
#define STRING_HEADER
#include <string.h>
#endif
#ifndef INPUT_HEADER
#define INPUT_HEADER
enum stages {
STAGE_1 = 1,
STAGE_2 = 2,
STAGE_3 = 3,
STAGE_4 = 4,
STAGE_ERROR = -1
};
/* Gets the current stage from the command-line argument */
enum stages getStage(char *stage);
/* Checks the validity of the command line input arguments */
void checkInputArgs(int argc, char **argv);
/* Gets the expected number of arguments for a given stage */
int getExpectedArgs(enum stages stage);
/* Prints the corresponding usage strings for a given stage */
void printArgError(enum stages stage, char *errorMessage);
/* Opens a file and checks if the file is safe to use */
FILE *safeFileOpen(FILE **f, char *fileName, char *mode);
#endif

BIN
input.o Normal file

Binary file not shown.

138
main.c Normal file
View file

@ -0,0 +1,138 @@
/* main.c
*
* Created by Rory Healy (healyr@student.unimelb.edu.au)
* Created on 25th August 2021
* Last modified 8th September 2021
*
* Lists the watchtowers that are in each face of the polygon.
* The polygon can be split using a pair of integers, which represent
* the edge numbers that should be connected. This comes from stdin.
*
* To run the program type:
* ./voronoi1 dataset_file polygon_file output_file < splits
*
* Options:
* dataset_file required Path to the dataset file (CSV)
* polygon_file required Path to the polygon file (txt)
* output_file required Output solution file
* splits optional Pairs of integers to split the edges
*
*/
#ifndef DCEL_HEADER
#include "dcel.h"
#endif
#ifndef COMMON_HEADER
#include "common.h"
#endif
#ifndef VORONOI_HEADER
#include "voronoi.h"
#endif
#ifndef INPUT_HEADER
#include "input.h"
#endif
// int main(int argc, char **argv) {
// /* Input and output files */
// FILE *datasetFile = NULL, *polygonFile = NULL, *outputFile = NULL;
// checkInputArgs(argc, argv, &datasetFile, &polygonFile, &outputFile);
// /* Stores information about the towers given in dataset file */
// tower_t **towers = malloc(sizeof(*towers));
// checkNullPointer(towers);
// int numTowers = 0;
// towers = readTowers(towers, datasetFile, &numTowers);
// /* Stores information about the vertices in the polygon file */
// vertex_t **vertices = malloc(sizeof(*vertices));
// checkNullPointer(vertices);
// int numVertices = 0;
// vertices = readPolygon(vertices, polygonFile, &numVertices);
// /* Create DCEL structure from vertices */
// /* Check for splits, split the polygon if needed */
// /* Counts towers in each polygon, outputs to outputFile */
// /* Cleaning up data */
// freeTowers(towers, numTowers);
// freeVertices(vertices, numVertices);
// fclose(datasetFile);
// fclose(polygonFile);
// fclose(outputFile);
// return 0;
// }
int main(int argc, char **argv) {
/* Ensure input arguments are correct */
enum stages stage = getStage(argv[1]);
int expectedArgs = getExpectedArgs(stage);
if (expectedArgs != argc) {
printArgError(stage, "Incorrect number of inputs.");
}
/* Then run the program according to the stage given */
switch(stage) {
/* Expected usage: ./voronoi2 1 pointsFile outputFile */
case STAGE_1: {
FILE *pointsFile = NULL, *outputFile = NULL;
pointsFile = safeFileOpen(&pointsFile, argv[2], "r");
outputFile = safeFileOpen(&outputFile, argv[3], "w");
fclose(pointsFile);
fclose(outputFile);
break;
}
/* Expected usage: ./voronoi2 2 pointsFile polygonFile outputFile */
case STAGE_2: {
FILE *pointsFile = NULL, *polygonFile = NULL, *outputFile = NULL;
pointsFile = safeFileOpen(&pointsFile, argv[2], "r");
polygonFile = safeFileOpen(&polygonFile, argv[3], "r");
outputFile = safeFileOpen(&outputFile, argv[4], "w");
fclose(pointsFile);
fclose(polygonFile);
fclose(outputFile);
break;
}
/* Expected usage: ./voronoi2 3 dataFile polygonFile outputFile */
case STAGE_3: {
FILE *dataFile = NULL, *polygonFile = NULL, *outputFile = NULL;
dataFile = safeFileOpen(&dataFile, argv[2], "r");
polygonFile = safeFileOpen(&polygonFile, argv[3], "r");
outputFile = safeFileOpen(&outputFile, argv[4], "w");
fclose(dataFile);
fclose(polygonFile);
fclose(outputFile);
break;
}
/* Expected usage: /voronoi2 4 dataFile polygonFile outputFile */
case STAGE_4: {
FILE *dataFile = NULL, *polygonFile = NULL, *outputFile = NULL;
dataFile = safeFileOpen(&dataFile, argv[2], "r");
polygonFile = safeFileOpen(&polygonFile, argv[3], "r");
outputFile = safeFileOpen(&outputFile, argv[4], "w");
fclose(dataFile);
fclose(polygonFile);
fclose(outputFile);
break;
}
/* Return error if stage number isn't defined. */
case STAGE_ERROR:
default:
fprintf(stderr, "Stage was not handled ENUM value (%d)\n", stage);
exit(EXIT_FAILURE);
}
return 0;
}

BIN
main.o Normal file

Binary file not shown.

0
output.txt Normal file
View file

8
polygon_irregular.txt Normal file
View file

@ -0,0 +1,8 @@
142.993000 -33.122900
147.597600 -33.221400
150.054600 -36.590100
150.400400 -39.229900
147.779600 -40.333100
144.412600 -40.195200
140.736200 -39.289000
140.335800 -37.476600

4
polygon_square.txt Normal file
View file

@ -0,0 +1,4 @@
140.9 -39.2
140.9 -33.9
150.0 -33.9
150.0 -39.2

12
pp_horizontal.txt Normal file
View file

@ -0,0 +1,12 @@
1.0 1.0 2.0 1.0
1.0 1.0 3.0 1.0
1.0 1.0 4.0 1.0
1.0 1.0 5.0 1.0
0.0 1.0 1.0 1.0
0.0 1.0 2.0 1.0
0.0 1.0 3.0 1.0
0.0 1.0 4.0 1.0
0.0 2.0 4.0 2.0
0.0 3.0 4.0 3.0
0.0 4.0 4.0 4.0
0.0 0.0 4.0 0.0

6
pp_inside.txt Normal file
View file

@ -0,0 +1,6 @@
145.6 -34.2 145.6 -35.2
145.6 -34.2 145.6 -36.2
145.6 -35.2 148.6 -35.2
147.6 -35.2 146.6 -35.2
148.6 -35.2 146.6 -35.2
148.6 -34.2 146.6 -32.2

6
pp_vertical.txt Normal file
View file

@ -0,0 +1,6 @@
0.0 0.0 0.0 1.0
0.0 0.0 0.0 2.0
0.0 1.0 0.0 2.0
1.0 1.0 1.0 2.0
2.0 1.0 2.0 2.0
3.0 1.0 3.0 2.0

122
voronoi.c Normal file
View file

@ -0,0 +1,122 @@
/* voronoi.c
*
* Created by Rory Healy (healyr@student.unimelb.edu.au)
* Created on 12th August 2021
* Last modified 25th August 2021
*
* Contains functions involving the reading of the dataset CSV file.
*
*/
#ifndef COMMON_HEADER
#include "common.h"
#endif
#ifndef VORONOI_HEADER
#include "voronoi.h"
#endif
#include <string.h>
#define BASE_10 10
#define MAX_CSV_ENTRY_LEN 512
#define MAX_FIELD_LEN 128
#define NUM_CSV_FIELDS 6
struct tower {
char *id;
char *postcode;
char *manager;
int population;
double x;
double y;
};
/* Reads the CSV file and stores the information in the towers array. */
tower_t **readTowers(tower_t **towers, FILE* datasetFile, int *numTowers) {
/* Maximum length of a single CSV line */
size_t lineBufferSize = MAX_CSV_ENTRY_LEN + 1;
/* Stores the current line from the CSV */
char *lineBuffer = malloc(lineBufferSize * sizeof(char));
checkNullPointer(lineBuffer);
int maxSizetowers = 1;
/* Discard the header line, then read the rest of the CSV */
getline(&lineBuffer, &lineBufferSize, datasetFile);
while (getline(&lineBuffer, &lineBufferSize, datasetFile) > 0) {
/* Check if there enough space in the towers array */
if (*numTowers == maxSizetowers) {
maxSizetowers *= 2;
tower_t **temp = realloc(towers, maxSizetowers * sizeof(*towers));
checkNullPointer(temp);
towers = temp;
}
/* The current tower being filled in with information */
towers[*numTowers] = malloc(sizeof(*towers[*numTowers]));
readCurrentLine(lineBuffer, towers[*numTowers]);
*numTowers += 1;
}
free(lineBuffer);
return towers;
}
/* Takes a line from the CSV and converts the data into a tower_t format */
void readCurrentLine(char* lineBuffer, tower_t* tower) {
/* Stores the current CSV field for the current line */
char *token = strtok(lineBuffer, ",");
size_t tokenLength;
for (int i = 0; i < NUM_CSV_FIELDS; i++) {
tokenLength = strlen(token);
switch(i) {
/* Case 0, 1, and 3 deal with strings
* Case 2 deals with an integer
* Case 4 and 5 deal with doubles
* Each case is handled seperately to fill in the
* tower with no space wasted.
*/
case 0:
tower->id = malloc(sizeof(char) * tokenLength + 1);
checkNullPointer(tower->id);
strcpy(tower->id, token);
tower->id[tokenLength] = '\0';
break;
case 1:
tower->postcode = malloc(sizeof(char) * tokenLength + 1);
checkNullPointer(tower->postcode);
strcpy(tower->postcode, token);
tower->postcode[tokenLength] = '\0';
break;
case 2:
tower->population = strtol(token, NULL, BASE_10);
break;
case 3:
tower->manager = malloc(sizeof(char) * tokenLength + 1);
checkNullPointer(tower->manager);
strcpy(tower->manager, token);
tower->manager[tokenLength] = '\0';
break;
case 4:
tower->x = strtod(token, NULL);
break;
case 5:
tower->y = strtod(token, NULL);
break;
}
token = strtok(NULL, ",");
}
}
void freeTowers(tower_t **towers, int numTowers) {
for (int i = 0; i < numTowers; i++) {
free(towers[i]->id);
free(towers[i]->manager);
free(towers[i]->postcode);
free(towers[i]);
}
free(towers);
}

25
voronoi.h Normal file
View file

@ -0,0 +1,25 @@
#ifndef STDIO_HEADER
#define STDIO_HEADER
#include <stdio.h>
#endif
#ifndef STDLIB_HEADER
#define STDLIB_HEADER
#include <stdlib.h>
#endif
#ifndef VORONOI_HEADER
#define VORONOI_HEADER
typedef struct tower tower_t;
tower_t** readTowers(tower_t **towers, FILE* datasetFile, int *numTowers);
void readCurrentLine(char* lineBuffer, tower_t* tower);
void freeTowers(tower_t **towers, int numTowers);
#endif

BIN
voronoi.o Normal file

Binary file not shown.

BIN
voronoi1 Normal file

Binary file not shown.

BIN
voronoi2 Executable file

Binary file not shown.