Add graph coloring assignment.

This commit is contained in:
2019-12-10 19:10:57 -05:00
parent c21240d9ea
commit 9479593281
40 changed files with 1661248 additions and 0 deletions

8
coloring/_coursera Normal file
View File

@@ -0,0 +1,8 @@
wNBw6FwlEeaEFQ4KWsLmjw
Graph Coloring
fmYLC, ./data/gc_50_3, solver.py, Coloring Problem 1
IkKpq, ./data/gc_70_7, solver.py, Coloring Problem 2
pZOjO, ./data/gc_100_5, solver.py, Coloring Problem 3
XDQ31, ./data/gc_250_9, solver.py, Coloring Problem 4
w7hAO, ./data/gc_500_1, solver.py, Coloring Problem 5
tthbm, ./data/gc_1000_5, solver.py, Coloring Problem 6

50288
coloring/data/gc_1000_1 Normal file

File diff suppressed because it is too large Load Diff

149456
coloring/data/gc_1000_3 Normal file

File diff suppressed because it is too large Load Diff

249483
coloring/data/gc_1000_5 Normal file

File diff suppressed because it is too large Load Diff

349871
coloring/data/gc_1000_7 Normal file

File diff suppressed because it is too large Load Diff

449736
coloring/data/gc_1000_9 Normal file

File diff suppressed because it is too large Load Diff

483
coloring/data/gc_100_1 Normal file
View File

@@ -0,0 +1,483 @@
100 482
0 4
0 34
0 49
0 52
0 55
0 68
0 80
0 93
1 3
1 14
1 36
1 49
1 63
1 64
1 65
1 79
1 83
1 91
1 93
1 94
2 11
2 17
2 28
2 31
2 55
2 70
3 21
3 27
3 39
3 53
3 54
3 59
3 61
3 68
3 80
3 83
3 87
3 89
3 91
3 93
4 25
4 29
4 36
4 38
4 45
4 90
4 91
4 96
5 9
5 10
5 25
5 35
5 55
5 56
5 66
5 69
5 70
5 74
5 77
5 84
5 96
5 99
6 10
6 18
6 26
6 44
6 82
6 83
6 99
7 14
7 21
7 37
7 76
7 78
7 88
7 93
8 22
8 26
8 40
8 43
8 53
8 70
8 92
9 65
9 80
9 90
10 15
10 16
10 39
10 40
10 46
10 47
10 50
10 71
10 74
10 82
11 18
11 20
11 23
11 41
11 42
11 48
11 53
11 56
11 63
11 71
11 73
11 77
11 80
11 81
12 21
12 22
12 36
12 45
12 57
12 72
12 87
12 88
12 91
12 94
12 99
13 17
13 24
13 71
13 79
13 99
14 24
14 27
14 35
14 48
14 53
14 69
14 77
14 82
14 85
14 88
14 96
15 33
15 41
15 42
15 45
15 52
15 54
15 56
15 75
15 89
15 93
16 19
16 27
16 30
16 51
16 86
17 49
17 64
17 82
17 88
17 94
17 99
18 27
18 28
18 55
18 62
18 65
18 95
19 20
19 36
19 37
19 46
19 49
19 50
19 77
19 93
19 96
20 25
20 31
20 33
20 56
20 81
20 88
21 32
21 37
21 45
21 46
21 68
21 69
21 80
21 89
22 29
22 34
22 49
22 57
22 62
22 82
22 88
22 90
22 95
23 25
23 29
23 33
23 41
23 45
23 62
23 64
23 76
23 83
23 90
24 26
24 36
24 41
24 43
24 71
24 80
24 83
24 92
24 98
25 37
25 52
25 60
25 62
25 66
25 80
25 93
26 28
26 35
26 39
26 65
26 79
26 81
26 87
26 90
26 92
27 37
27 47
27 56
27 62
27 71
27 83
27 89
27 90
28 31
28 32
28 51
28 56
28 61
28 68
28 82
29 31
29 39
29 58
29 61
29 81
29 83
29 90
30 32
30 46
30 50
30 57
30 62
30 63
30 64
30 80
30 83
31 48
31 59
31 76
32 34
32 35
32 38
32 49
32 58
32 85
32 87
33 41
33 44
33 47
33 51
33 57
33 62
33 64
33 74
33 82
33 93
33 94
33 98
34 46
34 47
34 49
34 75
34 82
34 86
34 88
34 95
35 50
35 64
35 73
35 80
35 84
35 85
35 95
36 46
36 47
36 53
36 68
36 70
36 74
36 86
36 88
36 95
37 44
37 67
37 96
38 58
38 60
38 65
38 76
38 91
39 61
39 62
39 90
40 55
40 67
40 78
40 88
40 92
40 93
41 47
41 50
41 59
41 63
41 67
41 87
41 88
41 96
42 49
42 58
42 72
42 84
43 47
43 59
43 74
43 76
43 79
43 90
43 98
44 45
44 50
44 52
44 53
44 58
44 64
44 78
44 89
44 94
44 98
45 47
45 73
45 88
45 98
46 55
46 80
46 85
46 86
46 95
46 99
47 50
47 68
47 74
47 76
47 87
48 49
48 51
48 54
48 56
48 88
48 94
49 56
49 64
49 65
49 85
49 87
49 92
50 74
51 88
51 89
51 93
52 53
52 74
52 96
53 57
53 64
53 72
53 82
54 61
54 69
54 79
54 82
54 83
54 86
54 93
55 65
56 66
56 77
57 66
57 67
57 95
58 70
58 76
58 77
59 68
59 86
59 87
59 92
60 71
60 74
60 78
60 92
60 99
62 69
62 88
62 97
63 69
63 86
64 70
64 82
65 75
66 79
66 87
67 78
67 79
67 90
67 91
68 80
68 88
68 97
69 70
69 71
69 73
70 73
70 80
70 84
70 88
70 97
72 83
72 90
74 83
75 77
75 90
75 91
75 92
76 80
76 99
77 80
77 85
77 91
77 92
77 97
78 80
78 82
79 81
79 92
80 96
81 82
81 93
81 96
82 86
82 93
83 84
83 91
83 92
83 93
84 85
84 94
85 87
86 92
86 93
87 94
89 94
89 96
89 98
92 97
94 99
95 98

1501
coloring/data/gc_100_3 Normal file

File diff suppressed because it is too large Load Diff

2503
coloring/data/gc_100_5 Normal file

File diff suppressed because it is too large Load Diff

3428
coloring/data/gc_100_7 Normal file

File diff suppressed because it is too large Load Diff

4462
coloring/data/gc_100_9 Normal file

File diff suppressed because it is too large Load Diff

24
coloring/data/gc_20_1 Normal file
View File

@@ -0,0 +1,24 @@
20 23
0 16
1 2
1 6
1 7
1 8
2 11
2 16
2 17
3 14
3 16
3 17
4 7
4 13
4 17
5 6
5 11
6 18
9 12
10 13
11 17
13 15
15 17
16 19

64
coloring/data/gc_20_3 Normal file
View File

@@ -0,0 +1,64 @@
20 63
0 4
0 13
1 2
1 3
1 6
1 18
1 19
2 3
2 5
2 8
2 10
2 11
2 15
2 16
2 18
3 7
3 8
3 13
3 15
3 19
4 6
4 9
4 10
4 11
4 12
4 14
4 15
4 18
5 6
5 7
5 9
5 10
5 11
6 11
6 13
6 14
6 16
6 17
7 9
8 11
8 13
8 18
9 10
9 11
9 12
9 13
9 14
9 17
10 11
10 12
10 14
10 15
10 17
10 19
11 13
11 19
12 18
13 15
13 18
15 18
15 19
16 19
18 19

96
coloring/data/gc_20_5 Normal file
View File

@@ -0,0 +1,96 @@
20 95
0 3
0 6
0 7
0 8
0 11
0 12
0 13
0 14
0 19
1 5
1 6
1 9
1 10
1 13
1 15
1 16
1 19
2 5
2 6
2 8
2 10
2 13
2 14
2 15
2 16
2 17
2 18
3 8
3 9
3 11
3 12
3 13
3 15
3 17
3 19
4 5
4 6
4 7
4 12
4 14
4 15
4 16
4 17
4 19
5 6
5 7
5 9
5 11
5 12
5 16
5 19
6 8
6 9
6 11
6 12
6 13
6 14
6 15
6 18
7 9
7 12
7 16
7 17
7 19
8 9
8 14
8 15
8 16
8 18
9 13
9 16
9 17
9 18
10 11
10 14
10 16
10 18
11 13
11 18
12 13
12 15
12 17
12 18
13 15
13 16
13 17
13 18
13 19
14 18
14 19
15 16
15 17
16 19
17 18
17 19

131
coloring/data/gc_20_7 Normal file
View File

@@ -0,0 +1,131 @@
20 130
0 1
0 2
0 3
0 4
0 5
0 7
0 9
0 10
0 11
0 12
0 13
0 16
0 17
0 18
1 2
1 4
1 5
1 6
1 7
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
2 4
2 5
2 6
2 7
2 12
2 13
2 14
2 15
2 16
2 17
2 18
2 19
3 4
3 6
3 7
3 8
3 9
3 10
3 15
3 16
3 18
3 19
4 10
4 11
4 12
4 13
4 14
4 15
4 16
4 17
4 18
5 7
5 8
5 12
5 13
5 14
5 15
5 16
5 17
5 18
5 19
6 7
6 9
6 10
6 11
6 16
6 17
6 18
6 19
7 9
7 11
7 13
7 17
7 18
8 10
8 11
8 12
8 14
8 15
8 16
8 18
8 19
9 11
9 12
9 14
9 15
9 16
9 18
9 19
10 11
10 15
10 16
10 18
10 19
11 12
11 13
11 14
11 15
11 16
11 17
11 19
12 13
12 14
12 15
12 18
12 19
13 14
13 15
13 16
13 17
13 18
14 15
14 17
14 18
15 17
15 19
16 17
16 18
17 18
17 19
18 19

165
coloring/data/gc_20_9 Normal file
View File

@@ -0,0 +1,165 @@
20 164
0 1
0 2
0 3
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 16
0 17
0 18
0 19
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 18
1 19
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
2 15
2 16
2 17
2 19
3 4
3 5
3 6
3 7
3 8
3 10
3 11
3 12
3 13
3 14
3 15
3 17
3 18
3 19
4 5
4 6
4 7
4 9
4 10
4 11
4 13
4 14
4 15
4 16
4 17
4 18
4 19
5 6
5 7
5 9
5 10
5 11
5 12
5 13
5 14
5 16
5 17
5 18
5 19
6 7
6 8
6 10
6 11
6 12
6 13
6 14
6 15
6 16
6 17
6 18
6 19
7 8
7 9
7 10
7 11
7 12
7 13
7 15
7 17
7 18
7 19
8 9
8 10
8 11
8 12
8 13
8 14
8 15
8 16
8 17
8 18
8 19
9 11
9 12
9 13
9 14
9 15
9 16
9 17
9 18
9 19
10 11
10 12
10 14
10 15
10 16
10 17
10 19
11 12
11 13
11 14
11 15
11 16
11 17
11 18
11 19
12 14
12 17
12 18
12 19
13 14
13 15
13 16
13 17
13 18
14 17
14 18
14 19
15 16
15 19
16 18
17 18
17 19
18 19

3025
coloring/data/gc_250_1 Normal file

File diff suppressed because it is too large Load Diff

9308
coloring/data/gc_250_3 Normal file

File diff suppressed because it is too large Load Diff

15706
coloring/data/gc_250_5 Normal file

File diff suppressed because it is too large Load Diff

21751
coloring/data/gc_250_7 Normal file

File diff suppressed because it is too large Load Diff

28047
coloring/data/gc_250_9 Normal file

File diff suppressed because it is too large Load Diff

4
coloring/data/gc_4_1 Normal file
View File

@@ -0,0 +1,4 @@
4 3
0 1
1 2
1 3

12566
coloring/data/gc_500_1 Normal file

File diff suppressed because it is too large Load Diff

37529
coloring/data/gc_500_3 Normal file

File diff suppressed because it is too large Load Diff

62449
coloring/data/gc_500_5 Normal file

File diff suppressed because it is too large Load Diff

87371
coloring/data/gc_500_7 Normal file

File diff suppressed because it is too large Load Diff

112225
coloring/data/gc_500_9 Normal file

File diff suppressed because it is too large Load Diff

134
coloring/data/gc_50_1 Normal file
View File

@@ -0,0 +1,134 @@
50 133
0 5
0 15
0 32
0 44
0 47
1 4
1 22
1 47
2 5
2 7
2 14
2 22
2 30
2 33
2 42
3 7
3 11
3 12
3 25
3 47
3 49
4 13
4 24
4 45
5 14
5 41
5 44
6 8
6 33
6 49
7 8
7 18
7 30
7 41
7 43
7 47
8 10
8 26
8 32
8 36
8 39
8 47
9 24
9 48
10 18
10 24
10 32
10 40
10 41
10 47
11 13
11 19
11 27
11 36
11 48
11 49
12 23
12 24
12 41
13 33
14 23
14 26
14 45
15 21
15 25
15 29
15 48
16 18
16 19
16 24
16 27
16 30
16 39
16 46
17 19
17 20
17 23
17 44
17 49
18 22
18 30
18 37
19 26
19 36
19 38
19 41
19 46
20 30
20 40
21 35
21 40
21 48
22 34
22 35
22 37
23 39
25 37
25 38
25 46
25 49
26 27
26 43
26 47
27 42
27 43
27 46
27 47
27 49
28 43
28 44
29 40
29 45
30 38
30 40
30 47
31 32
31 35
32 36
32 44
32 48
33 34
33 40
35 39
37 48
38 48
39 46
40 43
41 49
44 45
44 47
45 49
46 47
47 49

351
coloring/data/gc_50_3 Normal file
View File

@@ -0,0 +1,351 @@
50 350
0 3
0 5
0 8
0 10
0 42
0 43
0 45
0 49
1 5
1 13
1 15
1 16
1 20
1 22
1 24
1 25
1 27
1 31
1 35
1 39
1 45
1 46
1 47
2 3
2 9
2 10
2 12
2 15
2 21
2 28
2 36
2 42
2 46
2 47
2 48
3 5
3 7
3 8
3 9
3 11
3 25
3 30
3 33
3 35
3 36
3 40
3 45
4 12
4 15
4 16
4 20
4 24
4 26
4 27
4 30
4 40
4 43
4 44
4 45
4 47
5 7
5 18
5 25
5 32
5 37
5 42
5 43
5 45
5 46
5 49
6 15
6 16
6 17
6 18
6 20
6 23
6 24
6 28
6 29
6 33
6 35
6 37
6 41
6 43
6 45
6 46
7 9
7 14
7 18
7 20
7 21
7 22
7 24
7 26
7 31
7 32
7 35
7 37
7 40
7 41
7 44
7 46
7 47
7 49
8 11
8 16
8 17
8 20
8 27
8 28
8 31
8 32
8 34
8 41
8 43
8 47
9 10
9 12
9 14
9 15
9 19
9 25
9 26
9 33
9 35
9 38
9 43
9 44
10 17
10 19
10 20
10 30
10 31
10 37
10 38
10 39
10 42
11 15
11 18
11 20
11 22
11 28
11 31
11 32
11 33
11 34
11 35
11 37
11 41
11 46
11 47
12 14
12 16
12 17
12 20
12 28
12 29
12 31
12 43
12 45
12 48
12 49
13 14
13 15
13 19
13 20
13 23
13 24
13 26
13 29
13 41
14 19
14 23
14 26
14 29
14 37
14 39
14 48
14 49
15 16
15 19
15 27
15 30
15 31
15 33
15 44
15 48
15 49
16 17
16 19
16 25
16 29
16 30
16 33
16 35
16 38
16 41
16 46
16 48
17 22
17 23
17 29
17 32
17 33
17 44
17 45
17 46
18 22
18 28
18 31
18 33
18 35
18 42
19 23
19 26
19 29
19 38
19 39
19 42
19 43
19 45
19 47
19 49
20 24
20 28
20 37
20 40
20 42
20 44
20 47
21 22
21 24
21 25
21 37
21 44
21 45
22 27
22 29
22 30
22 32
22 41
22 44
22 47
22 48
22 49
23 27
23 29
23 32
23 34
23 42
23 43
24 25
24 27
24 32
24 40
24 48
25 34
25 45
25 46
25 48
26 27
26 29
26 30
26 32
26 33
26 36
26 42
26 48
27 29
27 30
27 32
27 35
27 41
27 44
27 45
27 47
27 48
28 33
28 34
28 35
28 36
28 37
28 43
28 45
29 31
29 35
29 43
29 44
29 45
30 31
30 37
30 39
31 33
31 36
31 38
31 40
31 46
31 48
32 34
32 35
32 36
32 39
32 42
32 45
32 47
32 49
33 34
33 39
33 41
33 43
33 44
33 45
33 46
33 47
34 35
34 40
34 43
34 44
34 45
35 36
35 39
35 40
35 41
35 42
35 45
36 42
36 45
36 47
36 49
37 38
37 39
37 43
38 41
38 42
38 48
40 45
40 46
40 47
41 42
41 44
42 44
42 47
42 49
43 44
43 47
44 45
44 49
45 47
45 49
46 47

593
coloring/data/gc_50_5 Normal file
View File

@@ -0,0 +1,593 @@
50 592
0 3
0 5
0 6
0 7
0 9
0 11
0 12
0 13
0 14
0 15
0 18
0 19
0 20
0 23
0 24
0 26
0 27
0 28
0 30
0 31
0 33
0 36
0 38
0 40
0 41
0 43
0 44
0 46
0 48
1 7
1 8
1 9
1 11
1 13
1 14
1 15
1 18
1 19
1 20
1 21
1 23
1 24
1 29
1 37
1 42
1 45
1 48
1 49
2 3
2 4
2 6
2 7
2 10
2 12
2 13
2 15
2 17
2 18
2 20
2 21
2 22
2 27
2 28
2 29
2 32
2 33
2 34
2 38
2 39
2 41
2 42
2 46
2 48
3 5
3 6
3 7
3 8
3 10
3 12
3 13
3 14
3 16
3 19
3 20
3 24
3 26
3 29
3 30
3 31
3 34
3 35
3 37
3 38
3 40
3 41
3 42
3 46
3 48
3 49
4 7
4 9
4 10
4 11
4 12
4 17
4 18
4 19
4 20
4 22
4 23
4 24
4 25
4 26
4 27
4 30
4 32
4 35
4 36
4 37
4 39
4 40
4 42
4 43
4 45
4 46
4 47
4 48
4 49
5 7
5 8
5 9
5 11
5 13
5 16
5 21
5 22
5 24
5 25
5 28
5 30
5 31
5 34
5 35
5 37
5 38
5 40
5 41
5 43
5 44
5 47
6 7
6 11
6 12
6 13
6 14
6 16
6 17
6 20
6 21
6 23
6 26
6 28
6 29
6 30
6 31
6 32
6 34
6 38
6 41
6 44
6 46
7 8
7 13
7 21
7 25
7 27
7 28
7 30
7 33
7 37
7 39
7 44
7 47
7 49
8 9
8 11
8 16
8 17
8 18
8 19
8 22
8 26
8 28
8 29
8 30
8 32
8 35
8 36
8 37
8 40
8 41
8 46
8 48
8 49
9 11
9 12
9 14
9 15
9 17
9 20
9 21
9 23
9 25
9 33
9 35
9 38
9 42
9 43
9 44
9 45
9 48
9 49
10 12
10 16
10 18
10 20
10 29
10 34
10 37
10 38
10 39
10 41
10 42
10 44
10 46
10 48
10 49
11 12
11 14
11 16
11 18
11 20
11 22
11 26
11 28
11 31
11 33
11 34
11 35
11 37
11 41
11 42
11 47
11 49
12 14
12 16
12 20
12 24
12 25
12 27
12 28
12 30
12 34
12 36
12 39
12 41
12 44
12 46
12 48
12 49
13 16
13 18
13 19
13 20
13 21
13 23
13 25
13 27
13 30
13 31
13 33
13 35
13 36
13 37
13 38
13 39
13 41
13 42
13 43
13 47
13 48
13 49
14 16
14 17
14 20
14 22
14 23
14 29
14 30
14 31
14 32
14 33
14 35
14 36
14 42
14 43
14 48
14 49
15 16
15 18
15 19
15 21
15 25
15 26
15 28
15 29
15 33
15 35
15 36
15 37
15 39
15 45
15 48
15 49
16 17
16 18
16 20
16 21
16 27
16 28
16 29
16 32
16 33
16 36
16 37
16 38
16 39
16 40
16 44
16 45
16 47
16 49
17 18
17 19
17 26
17 28
17 29
17 31
17 33
17 34
17 39
17 40
17 41
17 42
17 43
17 45
17 46
17 48
17 49
18 23
18 26
18 29
18 31
18 32
18 33
18 34
18 35
18 39
18 41
18 45
18 48
18 49
19 22
19 23
19 24
19 25
19 30
19 34
19 35
19 37
19 38
19 40
19 41
19 42
19 43
19 45
19 48
20 23
20 24
20 25
20 28
20 30
20 34
20 41
20 45
20 46
20 48
20 49
21 22
21 24
21 25
21 29
21 31
21 32
21 34
21 38
21 42
21 44
21 46
21 47
22 23
22 25
22 27
22 35
22 38
22 40
22 43
22 45
22 46
22 47
22 48
22 49
23 28
23 30
23 31
23 33
23 35
23 36
23 39
23 43
23 44
23 45
23 47
23 48
24 25
24 29
24 33
24 34
24 35
24 36
24 37
24 38
24 40
24 41
24 44
24 45
24 48
24 49
25 26
25 27
25 29
25 32
25 40
25 41
25 42
25 43
25 44
25 47
26 28
26 29
26 30
26 31
26 32
26 34
26 42
26 44
26 46
26 48
26 49
27 37
27 39
27 40
27 41
27 42
27 46
28 30
28 31
28 34
28 40
28 41
28 43
28 46
28 48
29 30
29 31
29 33
29 34
29 35
29 39
29 40
29 41
29 43
29 44
30 33
30 34
30 35
30 38
30 39
30 40
30 42
30 43
30 44
30 45
30 47
30 48
30 49
31 33
31 35
31 36
31 37
31 38
31 40
31 42
31 43
31 44
31 46
32 35
32 36
32 39
32 43
32 44
32 46
32 49
33 37
33 43
33 44
33 47
33 49
34 35
34 36
34 37
34 38
34 39
34 40
34 41
34 42
34 43
34 45
34 48
35 37
35 43
35 44
35 46
35 47
35 48
36 37
36 44
36 45
36 47
36 48
37 39
37 42
37 43
37 44
37 45
37 48
37 49
38 40
38 44
38 47
38 49
39 40
39 44
39 45
39 47
39 49
40 41
40 43
40 47
40 49
41 42
41 43
41 44
41 46
41 47
41 49
42 43
42 44
42 45
43 44
43 46
43 48
44 45
44 46
44 48
44 49
45 48
45 49
46 47
46 48
47 48
47 49

866
coloring/data/gc_50_7 Normal file
View File

@@ -0,0 +1,866 @@
50 865
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10
0 11
0 12
0 13
0 14
0 15
0 17
0 21
0 22
0 23
0 24
0 25
0 26
0 27
0 29
0 30
0 32
0 33
0 34
0 35
0 36
0 37
0 38
0 39
0 42
0 46
0 47
1 3
1 4
1 5
1 9
1 10
1 11
1 12
1 15
1 16
1 18
1 20
1 21
1 22
1 23
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 33
1 35
1 36
1 37
1 40
1 42
1 43
1 44
1 46
1 48
1 49
2 3
2 5
2 6
2 8
2 9
2 10
2 11
2 12
2 14
2 15
2 16
2 19
2 20
2 21
2 23
2 24
2 26
2 27
2 28
2 30
2 31
2 35
2 36
2 40
2 41
2 43
2 45
2 46
2 47
2 48
2 49
3 4
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 15
3 18
3 19
3 20
3 21
3 22
3 23
3 24
3 25
3 26
3 27
3 28
3 29
3 30
3 31
3 32
3 33
3 37
3 38
3 39
3 40
3 41
3 44
3 46
3 47
3 48
4 5
4 6
4 8
4 9
4 10
4 11
4 12
4 14
4 15
4 17
4 18
4 19
4 20
4 21
4 24
4 26
4 27
4 32
4 33
4 35
4 36
4 37
4 38
4 39
4 40
4 42
4 43
4 44
4 45
4 46
4 47
4 48
4 49
5 6
5 9
5 10
5 13
5 15
5 16
5 17
5 19
5 21
5 22
5 25
5 27
5 28
5 29
5 30
5 31
5 32
5 33
5 34
5 35
5 36
5 37
5 40
5 42
5 43
5 44
5 45
5 47
5 48
5 49
6 7
6 8
6 9
6 10
6 11
6 12
6 15
6 16
6 17
6 19
6 21
6 22
6 23
6 27
6 28
6 30
6 31
6 32
6 33
6 35
6 36
6 37
6 38
6 39
6 41
6 44
6 45
6 48
6 49
7 9
7 13
7 15
7 16
7 17
7 18
7 19
7 20
7 21
7 22
7 23
7 24
7 25
7 27
7 28
7 29
7 30
7 31
7 33
7 34
7 35
7 37
7 38
7 40
7 41
7 45
7 47
7 48
8 9
8 11
8 12
8 14
8 16
8 17
8 18
8 21
8 22
8 23
8 24
8 27
8 28
8 30
8 33
8 34
8 35
8 36
8 37
8 38
8 39
8 40
8 41
8 42
8 43
8 44
8 47
9 11
9 12
9 13
9 14
9 16
9 17
9 18
9 19
9 21
9 22
9 23
9 26
9 27
9 28
9 29
9 34
9 35
9 38
9 39
9 40
9 41
9 43
9 46
9 48
9 49
10 11
10 12
10 13
10 14
10 16
10 17
10 18
10 19
10 20
10 21
10 22
10 23
10 24
10 25
10 26
10 27
10 28
10 30
10 32
10 33
10 35
10 36
10 38
10 39
10 40
10 41
10 42
10 45
10 48
10 49
11 12
11 13
11 14
11 15
11 16
11 17
11 18
11 19
11 20
11 21
11 22
11 23
11 24
11 25
11 27
11 28
11 29
11 30
11 31
11 32
11 33
11 34
11 35
11 36
11 37
11 38
11 39
11 40
11 41
11 42
11 43
11 45
11 46
11 47
11 48
11 49
12 14
12 16
12 17
12 19
12 20
12 21
12 22
12 24
12 25
12 26
12 28
12 29
12 30
12 31
12 32
12 36
12 38
12 40
12 41
12 42
12 44
12 46
12 48
12 49
13 15
13 17
13 19
13 21
13 22
13 24
13 25
13 26
13 27
13 28
13 29
13 30
13 31
13 32
13 34
13 35
13 36
13 37
13 38
13 39
13 40
13 41
13 42
13 44
13 45
13 46
13 48
13 49
14 15
14 17
14 18
14 19
14 20
14 22
14 23
14 24
14 25
14 27
14 28
14 29
14 30
14 31
14 32
14 33
14 35
14 36
14 37
14 38
14 39
14 43
14 44
14 45
14 47
14 49
15 18
15 19
15 21
15 24
15 25
15 26
15 27
15 30
15 31
15 32
15 33
15 34
15 38
15 39
15 42
15 43
15 44
15 45
15 47
15 48
15 49
16 17
16 18
16 19
16 20
16 26
16 27
16 29
16 31
16 33
16 34
16 35
16 37
16 38
16 41
16 44
16 45
16 47
16 48
16 49
17 19
17 20
17 21
17 23
17 27
17 28
17 29
17 30
17 31
17 32
17 33
17 34
17 35
17 36
17 38
17 40
17 42
17 43
17 45
17 46
17 47
18 19
18 20
18 22
18 23
18 25
18 26
18 28
18 29
18 30
18 31
18 32
18 33
18 34
18 35
18 36
18 38
18 39
18 40
18 41
18 43
18 44
18 45
18 46
18 47
18 48
18 49
19 24
19 27
19 28
19 29
19 30
19 31
19 32
19 34
19 35
19 36
19 37
19 39
19 40
19 41
19 42
19 43
19 45
19 46
19 48
19 49
20 23
20 24
20 25
20 26
20 28
20 31
20 33
20 34
20 35
20 39
20 40
20 41
20 42
20 43
20 46
20 47
20 48
21 22
21 25
21 26
21 27
21 28
21 29
21 31
21 32
21 34
21 35
21 37
21 38
21 40
21 41
21 43
21 44
21 46
21 47
21 48
22 23
22 24
22 25
22 26
22 27
22 28
22 29
22 30
22 33
22 34
22 35
22 36
22 38
22 39
22 41
22 42
22 43
22 45
22 46
22 47
22 48
23 24
23 26
23 29
23 30
23 31
23 32
23 33
23 34
23 35
23 36
23 37
23 38
23 40
23 41
23 42
23 43
23 44
23 45
23 47
23 48
23 49
24 25
24 26
24 28
24 29
24 30
24 32
24 34
24 35
24 36
24 38
24 39
24 40
24 41
24 42
24 46
24 47
24 48
25 26
25 27
25 28
25 29
25 30
25 31
25 32
25 33
25 34
25 39
25 40
25 41
25 44
25 45
25 46
25 48
25 49
26 27
26 28
26 31
26 32
26 35
26 37
26 38
26 41
26 42
26 43
26 44
26 45
26 47
26 48
27 28
27 29
27 31
27 32
27 33
27 34
27 35
27 36
27 40
27 42
27 43
27 44
27 48
28 30
28 31
28 33
28 34
28 36
28 37
28 38
28 39
28 40
28 41
28 43
28 47
29 31
29 33
29 34
29 36
29 37
29 39
29 40
29 41
29 42
29 43
29 44
29 45
29 47
29 49
30 31
30 32
30 34
30 36
30 38
30 39
30 41
30 42
30 45
30 46
30 48
30 49
31 32
31 33
31 35
31 36
31 37
31 38
31 39
31 40
31 41
31 43
31 44
31 45
31 46
31 47
31 48
31 49
32 33
32 34
32 35
32 36
32 37
32 38
32 40
32 41
32 42
32 44
32 45
32 46
32 47
32 49
33 34
33 35
33 37
33 38
33 39
33 41
33 42
33 43
33 44
33 45
33 47
33 48
33 49
34 35
34 36
34 37
34 38
34 39
34 40
34 43
34 44
34 46
34 48
34 49
35 36
35 37
35 38
35 40
35 42
35 43
35 46
35 47
35 49
36 37
36 38
36 39
36 40
36 41
36 42
36 43
36 44
36 45
36 46
36 47
36 49
37 38
37 40
37 41
37 42
37 43
37 44
37 45
37 46
37 47
37 48
37 49
38 39
38 40
38 41
38 42
38 43
38 45
38 46
38 47
38 49
39 40
39 41
39 42
39 43
39 44
39 45
39 46
39 47
39 48
39 49
40 41
40 42
40 43
40 45
40 46
40 47
40 48
40 49
41 43
41 48
42 43
42 48
42 49
43 44
43 45
43 47
43 48
43 49
44 45
44 47
45 46
46 47
46 48
46 49
47 48
47 49
48 49

1104
coloring/data/gc_50_9 Normal file

File diff suppressed because it is too large Load Diff

225
coloring/data/gc_70_1 Normal file
View File

@@ -0,0 +1,225 @@
70 224
0 6
0 9
0 20
0 34
0 39
0 40
0 41
0 47
0 49
0 62
1 2
1 4
1 9
1 31
1 50
1 52
1 65
2 8
2 10
2 13
2 24
2 29
2 35
2 38
2 45
2 53
2 57
2 61
2 63
2 69
3 11
3 30
3 32
3 46
3 49
3 52
3 56
3 57
3 59
3 66
4 42
4 45
4 54
4 63
4 64
4 66
5 43
5 66
6 19
6 24
6 35
6 36
6 51
6 54
6 62
7 16
7 17
7 28
7 33
7 36
7 49
7 51
8 18
8 26
8 39
8 41
8 47
8 64
9 24
9 43
9 49
9 59
9 61
9 62
9 65
9 68
10 27
10 30
10 31
10 47
10 53
11 12
11 16
11 37
11 47
11 62
11 65
12 33
12 57
12 59
13 17
13 19
13 42
13 51
13 52
13 57
13 63
13 68
14 22
14 43
14 55
15 19
15 26
15 34
15 48
15 50
15 67
16 51
17 19
17 21
17 22
17 29
17 33
17 50
17 67
17 69
18 23
18 54
19 23
19 33
19 40
19 48
19 51
19 61
19 62
19 68
20 33
20 44
21 22
21 26
21 28
21 30
21 35
22 27
22 59
22 66
23 27
23 35
23 54
23 55
24 27
24 35
24 36
25 31
25 65
25 66
26 41
27 47
27 62
28 40
28 41
28 61
28 63
29 42
29 54
29 56
30 33
30 36
30 41
30 47
30 56
30 60
31 57
32 33
32 37
33 42
33 46
34 50
34 52
34 59
35 36
35 57
36 38
36 49
36 51
37 38
37 48
38 43
40 41
40 42
40 48
40 49
40 54
40 55
40 68
41 45
41 46
41 48
41 60
41 64
42 48
42 52
42 56
43 51
43 52
44 49
44 53
44 66
45 52
45 57
46 51
46 53
46 54
46 56
47 50
48 51
48 56
48 61
49 67
50 57
50 69
51 63
52 58
52 60
53 62
54 62
54 66
54 69
56 59
56 61
56 63
59 62
61 63
66 67

722
coloring/data/gc_70_3 Normal file
View File

@@ -0,0 +1,722 @@
70 721
0 8
0 9
0 10
0 15
0 19
0 21
0 22
0 24
0 25
0 28
0 30
0 33
0 36
0 44
0 47
0 48
0 49
0 51
0 53
0 54
0 61
0 63
0 64
0 65
0 66
1 3
1 6
1 10
1 17
1 18
1 19
1 21
1 22
1 29
1 31
1 34
1 36
1 37
1 39
1 40
1 41
1 47
1 48
1 51
1 55
1 64
1 66
1 68
2 4
2 6
2 8
2 19
2 26
2 27
2 28
2 35
2 38
2 39
2 40
2 42
2 45
2 48
2 49
2 53
2 59
2 60
2 63
2 68
3 9
3 12
3 13
3 14
3 19
3 20
3 22
3 23
3 24
3 25
3 33
3 36
3 39
3 40
3 44
3 48
3 49
3 51
3 52
3 53
3 56
3 62
3 65
4 5
4 6
4 19
4 21
4 22
4 23
4 24
4 27
4 29
4 40
4 41
4 42
4 43
4 44
4 46
4 47
4 51
4 53
4 56
4 63
4 64
4 65
4 66
4 69
5 7
5 26
5 27
5 30
5 33
5 41
5 42
5 46
5 54
5 57
5 58
5 63
5 64
5 67
5 68
6 11
6 16
6 18
6 20
6 26
6 30
6 34
6 42
6 46
6 50
6 59
6 62
7 10
7 17
7 19
7 26
7 27
7 34
7 38
7 41
7 42
7 44
7 45
7 47
7 49
7 50
7 67
8 14
8 23
8 27
8 32
8 33
8 37
8 42
8 43
8 46
8 50
8 55
8 56
8 62
8 67
8 69
9 10
9 11
9 15
9 16
9 23
9 25
9 29
9 34
9 42
9 50
9 53
9 54
9 55
9 56
9 59
9 61
9 64
9 69
10 12
10 18
10 19
10 21
10 34
10 38
10 39
10 40
10 42
10 43
10 44
10 46
10 52
10 54
10 55
10 56
10 58
10 64
10 66
11 13
11 14
11 20
11 23
11 32
11 34
11 35
11 37
11 38
11 42
11 45
11 46
11 50
11 52
11 53
11 54
11 56
11 57
11 58
11 59
11 60
11 64
11 66
12 15
12 19
12 22
12 24
12 36
12 40
12 52
12 54
12 55
12 56
12 59
12 60
12 65
12 67
12 69
13 14
13 16
13 17
13 19
13 21
13 33
13 38
13 41
13 46
13 52
14 15
14 18
14 19
14 25
14 30
14 39
14 40
14 46
14 50
14 52
14 54
14 58
14 59
14 60
14 61
14 65
14 68
14 69
15 19
15 20
15 21
15 23
15 25
15 32
15 33
15 34
15 37
15 38
15 42
15 43
15 44
15 46
15 48
15 50
15 52
15 54
15 58
15 63
15 64
16 18
16 19
16 20
16 26
16 29
16 42
16 43
16 46
16 51
16 62
16 67
17 19
17 24
17 26
17 27
17 30
17 32
17 35
17 38
17 44
17 47
17 49
17 50
17 51
17 57
17 58
17 62
17 64
17 68
18 20
18 23
18 26
18 27
18 30
18 37
18 41
18 53
18 57
18 63
18 64
18 67
18 68
19 20
19 26
19 27
19 29
19 32
19 33
19 44
19 45
19 48
19 49
19 50
19 51
19 57
19 58
19 60
19 62
19 65
19 67
19 68
20 23
20 24
20 26
20 28
20 30
20 38
20 43
20 44
20 56
20 58
20 62
20 67
20 68
20 69
21 39
21 44
21 46
21 52
21 53
21 54
21 55
21 56
21 59
21 62
21 63
21 69
22 26
22 27
22 28
22 31
22 36
22 38
22 41
22 42
22 45
22 54
22 56
22 59
22 60
22 61
22 63
22 65
22 69
23 29
23 30
23 34
23 36
23 38
23 46
23 63
23 69
24 26
24 32
24 47
24 48
24 49
24 51
24 58
24 61
24 67
25 29
25 36
25 40
25 41
25 43
25 44
25 47
25 51
25 56
25 66
25 69
26 27
26 28
26 34
26 36
26 44
26 51
26 54
26 55
26 57
26 58
26 61
26 63
26 68
27 30
27 32
27 34
27 40
27 42
27 52
27 54
27 56
27 61
28 30
28 38
28 41
28 42
28 43
28 45
28 50
28 51
28 53
28 54
28 55
28 56
28 58
28 60
28 63
28 64
28 68
28 69
29 31
29 32
29 35
29 42
29 46
29 49
29 55
29 56
29 58
29 63
29 64
30 31
30 34
30 37
30 39
30 41
30 43
30 44
30 52
30 53
30 54
30 58
30 62
30 65
30 68
31 33
31 41
31 43
31 44
31 47
31 48
31 57
31 58
31 61
31 66
31 68
32 37
32 38
32 39
32 44
32 48
32 50
32 65
33 34
33 37
33 42
33 43
33 45
33 47
33 49
33 55
33 58
33 59
33 62
33 63
33 66
34 35
34 40
34 41
34 50
34 55
34 57
34 59
34 61
34 63
34 67
34 69
35 38
35 39
35 40
35 44
35 47
35 57
35 60
35 62
35 63
35 68
36 38
36 39
36 43
36 45
36 46
36 48
36 49
36 52
36 54
36 59
36 64
36 65
36 66
36 69
37 38
37 44
37 50
37 57
37 60
37 65
37 68
37 69
38 40
38 42
38 43
38 46
38 54
38 62
38 64
39 41
39 42
39 44
39 47
39 49
39 53
39 55
39 58
39 60
39 64
39 69
40 41
40 47
40 51
40 52
40 56
40 57
40 58
40 61
40 67
41 50
41 51
41 54
41 57
41 62
41 63
41 69
42 44
42 45
42 46
42 48
42 49
42 54
42 56
42 60
42 64
42 66
42 68
43 46
43 51
43 52
43 53
43 56
43 57
43 60
43 64
43 65
43 69
44 47
44 48
44 50
44 53
44 54
44 57
44 59
44 66
44 68
45 47
45 50
45 57
45 61
45 64
45 66
45 67
45 69
46 47
46 50
46 52
46 56
46 57
46 63
46 66
46 68
47 56
47 63
47 64
47 65
47 69
48 51
48 52
48 57
48 61
48 65
48 66
48 67
49 52
49 61
49 63
49 64
49 66
50 60
50 62
50 64
50 68
51 52
51 53
51 56
51 58
51 60
51 61
51 63
52 55
52 64
52 65
52 66
52 69
53 57
53 60
53 65
53 66
53 68
54 55
54 56
54 57
54 59
54 63
54 67
55 57
55 60
55 64
55 65
55 68
56 60
56 61
56 63
56 65
56 69
57 67
57 68
57 69
58 59
58 64
58 67
59 62
59 67
60 62
61 62
61 63
61 64
61 66
61 69
62 65
63 69
64 65
64 67
65 68
67 68

1236
coloring/data/gc_70_5 Normal file

File diff suppressed because it is too large Load Diff

1679
coloring/data/gc_70_7 Normal file

File diff suppressed because it is too large Load Diff

2159
coloring/data/gc_70_9 Normal file

File diff suppressed because it is too large Load Diff

BIN
coloring/handout.pdf Normal file

Binary file not shown.

43
coloring/solver.py Normal file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
def solve_it(input_data):
# Modify this code to run your optimization algorithm
# parse the input
lines = input_data.split('\n')
first_line = lines[0].split()
node_count = int(first_line[0])
edge_count = int(first_line[1])
edges = []
for i in range(1, edge_count + 1):
line = lines[i]
parts = line.split()
edges.append((int(parts[0]), int(parts[1])))
# build a trivial solution
# every node has its own color
solution = range(0, node_count)
# prepare the solution in the specified output format
output_data = str(node_count) + ' ' + str(0) + '\n'
output_data += ' '.join(map(str, solution))
return output_data
import sys
if __name__ == '__main__':
import sys
if len(sys.argv) > 1:
file_location = sys.argv[1].strip()
with open(file_location, 'r') as input_data_file:
input_data = input_data_file.read()
print(solve_it(input_data))
else:
print('This test requires an input file. Please select one from the data directory. (i.e. python solver.py ./data/gc_4_1)')

456
coloring/submit.py Executable file
View File

@@ -0,0 +1,456 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import json
import time
import os
from collections import namedtuple
# Python 2/3 compatibility
# Python 2:
try:
from urlparse import urlparse
from urllib import urlencode
from urllib2 import urlopen, Request, HTTPError
except:
pass
# Python 3:
try:
from urllib.parse import urlparse, urlencode
from urllib.request import urlopen, Request
from urllib.error import HTTPError
except:
pass
import sys
# Python 2:
if sys.version_info < (3, 0):
def input(str):
return raw_input(str)
# Python 3, backward compatibility with unicode test
if sys.version_info >= (3, 0):
unicode = type(str)
version = '1.0.0'
submitt_url = \
'https://www.coursera.org/api/onDemandProgrammingScriptSubmissions.v1'
Metadata = namedtuple("Metadata", ['assignment_key', 'name', 'part_data'])
Part = namedtuple("Part", ['id', 'input_file', 'solver_file', 'name'])
def load_metadata(metadata_file_name='_coursera'):
'''
Parses an assignment metadata file
Args:
metadata_file_name (str): location of the metadata file
Returns:
metadata as a named tuple structure
'''
if not os.path.exists(metadata_file_name):
print('metadata file "%s" not found' % metadata_file_name)
quit()
try:
with open(metadata_file_name, 'r') as metadata_file:
url = metadata_file.readline().strip()
name = metadata_file.readline().strip()
part_data = []
for line in metadata_file.readlines():
if ',' in line:
line_parts = line.split(',')
line_parts = [x.strip() for x in line_parts]
assert(len(line_parts) == 4)
part_data.append(Part(*line_parts))
if len(url) <= 0:
print('Empty url in _coursera file: %s' % metadata_file_name)
quit()
if len(name) <= 0:
print('Empty assignment name in _coursera file: %s' % metadata_file_name)
quit()
except Exception as e:
print('problem parsing assignment metadata file')
print('exception message:')
print(e)
quit()
return Metadata(url, name, part_data)
def part_prompt(problems):
'''
Prompts the user for which parts of the assignment they would like to
submit.
Args:
problems: a list of assignment problems
Returns:
the selected subset of problems
'''
count = 1
print('Hello! These are the assignment parts that you can submit:')
for i, problem in enumerate(problems):
print(str(count) + ') ' + problem.name)
count += 1
print('0) All')
part_text = input('Please enter which part(s) you want to submit (0-%d): ' % (count-1))
selected_problems = []
selected_models = []
for item in part_text.split(','):
try:
i = int(item)
except:
print('Skipping input "' + item + '". It is not an integer.')
continue
if i >= count or i < 0:
print('Skipping input "' + item + '". It is out of the valid range (0-%d).' % (count-1))
continue
if i == 0:
selected_problems.extend(problems)
continue
if i <= len(problems):
selected_problems.append(problems[i-1])
if len(selected_problems) <= 0:
print('No valid assignment parts identified. Please try again. \n')
return part_prompt(problems)
else:
return selected_problems
def compute(metadata, solver_file_override=None):
'''
Determines which assignment parts the student would like to submit.
Then computes his/her answers to those assignment parts
Args:
metadata: the assignment metadata
solver_file_override: an optional model file to override the metadata
default
Returns:
a dictionary of results in the format Coursera expects
'''
if solver_file_override is not None:
print('Overriding solver file with: '+solver_file_override)
selected_problems = part_prompt(metadata.part_data)
results = {}
#submission needs empty dict for every assignment part
results.update({prob_data.id : {} for prob_data in metadata.part_data})
for problem in selected_problems:
if solver_file_override != None:
solver_file = solver_file_override
else:
solver_file = problem.solver_file
if not os.path.isfile(solver_file):
print('Unable to locate assignment file "%s" in the current working directory.' % solver_file)
continue
# if a relative path is given, add that patth to system path so import will work
if os.path.sep in solver_file:
split = solver_file.rfind(os.path.sep)
path = solver_file[0:split]
file_name = solver_file[split+1:]
sys.path.insert(0, path)
solver_file = file_name
submission = output(problem.input_file, solver_file)
if submission != None:
results[problem.id] = {'output':submission}
print('\n== Computations Complete ...')
return results
def load_input_data(file_location):
with open(file_location, 'r') as input_data_file:
input_data = ''.join(input_data_file.readlines())
return input_data
def output(input_file, solver_file):
'''
Attempts to execute solve_it locally on a given input file.
Args:
input_file: the assignment problem data of interest
solver_file: a python file containing the solve_it function
Returns:
the submission string in a format that the grader expects
'''
try:
pkg = __import__(solver_file[:-3]) # remove '.py' extension
if not hasattr(pkg, 'solve_it'):
print('the solve_it() function was not found in %s' % solver_file)
quit()
except ImportError:
print('import error with python file "%s".' % solver_file)
quit()
solution = ''
start = time.clock()
try:
solution = pkg.solve_it(load_input_data(input_file))
except Exception as e:
print('the solve_it(input_data) method from solver.py raised an exception')
print('try testing it with python ./solver.py before running this submission script')
print('exception message:')
print(str(e))
print('')
return 'Local Exception =('
end = time.clock()
if not (isinstance(solution, str) or isinstance(solution, unicode)):
print('Warning: the solver did not return a string. The given object will be converted with the str() method.')
solution = str(solution)
print('Submitting: ')
print(solution)
return solution.strip() + '\n' + str(end - start)
def login_dialog(assignment_key, results, credentials_file_location = '_credentials'):
'''
Requests Coursera login credentials from the student and submits the
student's solutions for grading
Args:
assignment_key: Coursera's assignment key
results: a dictionary of results in Cousera's format
credentials_file_location: a file location where login credentials can
be found
'''
success = False
tries = 0
while not success:
# stops infinate loop when credentials file is incorrect
if tries <= 0:
login, token = login_prompt(credentials_file_location)
else:
login, token = login_prompt('')
code, responce = submit_solution(assignment_key, login, token, results)
print('\n== Coursera Responce ...')
#print(code)
print(responce)
if code != 401:
success = True
else:
print('\ntry logging in again')
tries += 1
def login_prompt(credentials_file_location):
'''
Attempts to load credentials from a file, if that fails asks the user.
Returns:
the user's login and token
'''
if os.path.isfile(credentials_file_location):
try:
with open(credentials_file_location, 'r') as metadata_file:
login = metadata_file.readline().strip()
token = metadata_file.readline().strip()
metadata_file.close()
except:
login, token = basic_prompt()
else:
login, token = basic_prompt()
return login, token
def basic_prompt():
'''
Prompt the user for login credentials.
Returns:
the user's login and token
'''
login = input('User Name (e-mail address): ')
token = input('Submission Token (from the assignment page): ')
return login, token
def submit_solution(assignment_key, email_address, token, results):
'''
Sends the student's submission to Coursera for grading via the submission
API.
Args:
assignment_key: Coursera's assignment key
email_address: the student's email
token: the student's assignment token
results: a dictionary of results in Cousera's format
Returns:
the https response code and a feedback message
'''
print('\n== Connecting to Coursera ...')
print('Submitting %d of %d parts' %
(sum(['output' in v for k,v in results.items()]), len(results)))
# build json datastructure
parts = {}
submission = {
'assignmentKey': assignment_key,
'submitterEmail': email_address,
'secret': token,
'parts': results
}
# send submission
req = Request(submitt_url)
req.add_header('Cache-Control', 'no-cache')
req.add_header('Content-type', 'application/json')
try:
res = urlopen(req, json.dumps(submission).encode('utf8'))
except HTTPError as e:
responce = json.loads(e.read().decode('utf8'))
if 'details' in responce and responce['details'] != None and \
'learnerMessage' in responce['details']:
return e.code, responce['details']['learnerMessage']
else:
return e.code, 'Unexpected response code, please contact the ' \
'course staff.\nDetails: ' + responce['message']
code = res.code
responce = json.loads(res.read().decode('utf8'))
if code >= 200 and code <= 299:
return code, 'Your submission has been accepted and will be ' \
'graded shortly.'
return code, 'Unexpected response code, please contact the '\
'course staff.\nDetails: ' + responce
def main(args):
'''
1) Reads a metadata file to customize the submission process to
a particular assignment.
2) The compute the student's answers to the assignment parts.
3) Submits the student's answers for grading.
Provides the an option for saving the submissions locally. This is very
helpful when testing the assignment graders.
Args:
args: CLI arguments from an argparse parser
'''
# needed so that output can import from the cwd
sys.path.append(os.getcwd())
if args.metadata is None:
metadata = load_metadata()
else:
print('Overriding metadata file with: '+args.metadata)
metadata = load_metadata(args.metadata)
print('==\n== '+metadata.name+' Solution Submission \n==')
# compute dialog
results = compute(metadata, args.override)
if sum(['output' in v for k,v in results.items()]) <= 0:
return
# store submissions if requested
if args.record_submission == True:
print('Recording submission as files')
for sid, submission in results.items():
if 'output' in submission:
directory = '_'+sid
if not os.path.exists(directory):
os.makedirs(directory)
submission_file_name = directory+'/submission.sub'
print(' writting submission file: '+submission_file_name)
with open(submission_file_name,'w') as submission_file:
submission_file.write(submission['output'])
submission_file.close()
return
# submit dialog
if args.credentials is None:
login_dialog(metadata.assignment_key, results)
else:
print('Overriding credentials file with: '+args.credentials)
login_dialog(metadata.assignment_key, results, args.credentials)
import argparse
def build_parser():
'''
Builds an argument parser for the CLI
Returns:
parser: an argparse parser
'''
parser = argparse.ArgumentParser(
description='''The submission script for Discrete Optimization
assignments on the Coursera Platform.''',
epilog='''Please file bugs on github at:
https://github.com/discreteoptimization/assignment/issues. If you
would like to contribute to this tool's development, check it out at:
https://github.com/discreteoptimization/assignment'''
)
parser.add_argument('-v', '--version', action='version',
version='%(prog)s '+version)
parser.add_argument('-o', '--override',
help='overrides the python source file specified in the \'_coursera\' file')
parser.add_argument('-m', '--metadata',
help='overrides the \'_coursera\' metadata file')
parser.add_argument('-c', '--credentials',
help='overrides the \'_credentials\' credentials file')
parser.add_argument('-rs', '--record_submission',
help='records the submission(s) as files', action='store_true')
return parser
if __name__ == '__main__':
parser = build_parser()
main(parser.parse_args())