Skip to content

Commit d37a765

Browse files
committed
put all macro comments back in
1 parent 2eb6595 commit d37a765

40 files changed

+248
-27
lines changed

annealing.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void solution_count_update(tsp_solution *s, tsp_instance *t) {
2828
/* Use random sampling to provide a heuristic solution to a given
2929
optimization problem.
3030
*/
31-
31+
/* [[[ random_sampling_cut */
3232
void random_sampling(tsp_instance *t, int nsamples, tsp_solution *bestsol) {
3333
tsp_solution s; /* current tsp solution */
3434
double best_cost; /* best cost so far */
@@ -51,11 +51,13 @@ void random_sampling(tsp_instance *t, int nsamples, tsp_solution *bestsol) {
5151
solution_count_update(&s, t);
5252
}
5353
}
54+
/* ]]] */
5455

5556
/* Use hill climbing to provide a heuristic solution to a given
5657
optimization problem.
5758
*/
5859

60+
/* [[[ hill_climbing_cut */
5961
void hill_climbing(tsp_instance *t, tsp_solution *s) {
6062
double cost; /* best cost so far */
6163
double delta; /* swap cost */
@@ -83,6 +85,7 @@ void hill_climbing(tsp_instance *t, tsp_solution *s) {
8385
} while (stuck == TRUE);
8486

8587
}
88+
/* ]]] */
8689

8790
void repeated_hill_climbing(tsp_instance *t, int nsamples, tsp_solution *bestsol) {
8891
tsp_solution s; /* current tsp solution */
@@ -113,6 +116,7 @@ void repeated_hill_climbing(tsp_instance *t, int nsamples, tsp_solution *bestsol
113116
We are seeking to *minimize* the current_value.
114117
*/
115118

119+
/* [[[ anneal_cut */
116120
void anneal(tsp_instance *t, tsp_solution *s) {
117121
int i1, i2; /* pair of items to swap */
118122
int i, j; /* counters */
@@ -172,6 +176,7 @@ void anneal(tsp_instance *t, tsp_solution *s) {
172176
}
173177
}
174178
}
179+
/* ]]] */
175180

176181
void repeated_annealing(tsp_instance *t, int nsamples, tsp_solution *bestsol) {
177182
tsp_solution s; /* current tsp solution */

backtrack.c

+4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ This book can be ordered from Amazon.com at
3030
#include "backtrack.h"
3131
#include "bool.h"
3232

33+
/* [[[ backtrack_boolean_cut */
3334
bool finished = FALSE; /* found all solutions yet? */
35+
/* ]]] */
3436

3537
void process_solution(int a[], int k, data input);
3638
void construct_candidates(int a[], int k, data input, int c[], int *ncandidates);
3739
void make_move(int a[], int k, data input);
3840
void unmake_move(int a[], int k, data input);
3941
int is_a_solution(int a[], int k, data input);
4042

43+
/* [[[ backtrack_cut */
4144
void backtrack(int a[], int k, data input) {
4245
int c[MAXCANDIDATES]; /* candidates for next position */
4346
int ncandidates; /* next position candidate count */
@@ -60,3 +63,4 @@ void backtrack(int a[], int k, data input) {
6063
}
6164
}
6265
}
66+
/* ]]] */

bfs-demo.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,23 @@ extern bool processed[]; /* which vertices have been processed */
3535
extern bool discovered[]; /* which vertices have been found */
3636
extern int parent[]; /* discovery relation */
3737

38+
/* [[[ pvearly_cut */
3839
void process_vertex_early(int v) {
3940
printf("processed vertex %d\n", v);
4041
}
42+
/* ]]] */
4143

44+
/* [[[ pvlate_cut */
4245
void process_vertex_late(int v) {
4346

4447
}
48+
/* ]]] */
4549

46-
50+
/* [[[ pedge_cut */
4751
void process_edge(int x, int y) {
4852
printf("processed edge (%d,%d)\n", x, y);
4953
}
54+
/* ]]] */
5055

5156
int main(void) {
5257
graph g;

bfs-dfs.c

+12
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ This book can be ordered from Amazon.com at
3232
#include "bool.h"
3333
#include "queue.h"
3434

35+
/* [[[ graph_arrays_cut */
3536
bool processed[MAXV+1]; /* which vertices have been processed */
3637
bool discovered[MAXV+1]; /* which vertices have been found */
3738
int parent[MAXV+1]; /* discovery relation */
39+
/* ]]] */
3840

3941
int entry_time[MAXV+1]; /* time of vertex entry */
4042
int exit_time[MAXV+1]; /* time of vertex exit */
4143
int time; /* current event time */
4244

4345
bool finished = FALSE; /* if true, cut off search immediately */
4446

47+
/* [[[ init_search_cut */
4548
void initialize_search(graph *g) {
4649
int i; /* counter */
4750

@@ -53,7 +56,9 @@ void initialize_search(graph *g) {
5356
parent[i] = -1;
5457
}
5558
}
59+
/* ]]] */
5660

61+
/* [[[ bfs_cut */
5762
void bfs(graph *g, int start) {
5863
queue q; /* queue of vertices to visit */
5964
int v; /* current vertex */
@@ -84,7 +89,9 @@ void bfs(graph *g, int start) {
8489
process_vertex_late(v);
8590
}
8691
}
92+
/* ]]] */
8793

94+
/* [[[ eclass_cut */
8895
int edge_classification(int x, int y) {
8996
if (parent[y] == x) {
9097
return(TREE);
@@ -106,7 +113,9 @@ int edge_classification(int x, int y) {
106113

107114
return -1;
108115
}
116+
/* ]]] */
109117

118+
/* [[[ dfs_cut */
110119
void dfs(graph *g, int v) {
111120
edgenode *p; /* temporary pointer */
112121
int y; /* successor vertex */
@@ -146,7 +155,9 @@ void dfs(graph *g, int v) {
146155

147156
processed[v] = TRUE;
148157
}
158+
/* ]]] */
149159

160+
/* [[[ find_path_cut */
150161
void find_path(int start, int end, int parents[]) {
151162
if ((start == end) || (end == -1)) {
152163
printf("\n%d", start);
@@ -155,3 +166,4 @@ void find_path(int start, int end, int parents[]) {
155166
printf(" %d", end);
156167
}
157168
}
169+
/* ]]] */

biconnected.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ extern int parent[]; /* discovery relation */
3838
extern int entry_time[MAXV+1]; /* time of vertex entry */
3939
extern int exit_time[MAXV+1]; /* time of vertex exit */
4040

41+
/* [[[ ratod_cut */
4142
int reachable_ancestor[MAXV+1]; /* earliest reachable ancestor of v */
4243
int tree_out_degree[MAXV+1]; /* DFS tree outdegree of v */
44+
/* ]]] */
4345

46+
/* [[[ pvearlydfs_cut */
4447
void process_vertex_early(int v) {
4548
reachable_ancestor[v] = v;
4649
}
50+
/* ]]] */
4751

52+
/* [[[ pvlatedfs_cut */
4853
void process_vertex_late(int v) {
4954
bool root; /* is a given vertex the root of the DFS tree? */
5055
int time_v; /* earliest reachable time for v */
@@ -80,13 +85,14 @@ void process_vertex_late(int v) {
8085
reachable_ancestor[parent[v]] = reachable_ancestor[v];
8186
}
8287
}
88+
/* ]]] */
8389

90+
/* [[[ pedgedfs_cut */
8491
void process_edge(int x, int y) {
8592
int class; /* edge class */
8693

8794
class = edge_classification(x, y);
8895

89-
/*printf("(%d,%d) class %d tree_out_degree[%d]=%d\n", x,y,class,x,tree_out_degree[x]);*/
9096
if (class == TREE) {
9197
tree_out_degree[x] = tree_out_degree[x] + 1;
9298
}
@@ -97,6 +103,7 @@ void process_edge(int x, int y) {
97103
}
98104
}
99105
}
106+
/* ]]] */
100107

101108
void articulation_vertices(graph *g) {
102109
int i; /* counter */

binomial.c

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
/* computer n choose m */
1212

13+
/* [[[ binomial_coeff_cut */
1314
long binomial_coefficient(int n, int m) {
1415
int i, j; /* counters */
1516
long bc[MAXN][MAXN]; /* table of binomial coefficient values */
@@ -30,6 +31,7 @@ long binomial_coefficient(int n, int m) {
3031

3132
return(bc[n][m]);
3233
}
34+
/* ]]] */
3335

3436
int main(void) {
3537
int a, b;

bipartite.c

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ void process_vertex_late(int v) {
5353

5454
}
5555

56+
/* [[[ complement_cut */
5657
int complement(int color) {
5758
if (color == WHITE) {
5859
return(BLACK);
@@ -64,7 +65,9 @@ int complement(int color) {
6465

6566
return(UNCOLORED);
6667
}
68+
/* ]]] */
6769

70+
/* [[[ pecolor_cut */
6871
void process_edge(int x, int y) {
6972
if (color[x] == color[y]) {
7073
bipartite = FALSE;
@@ -73,7 +76,9 @@ void process_edge(int x, int y) {
7376

7477
color[y] = complement(color[x]);
7578
}
79+
/* ]]] */
7680

81+
/* [[[ twocolor_cut */
7782
void twocolor(graph *g) {
7883
int i; /* counter */
7984

@@ -92,6 +97,7 @@ void twocolor(graph *g) {
9297
}
9398
}
9499
}
100+
/* ]]] */
95101

96102
int main(void) {
97103
graph g;

connected.c

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void process_edge(int x, int y) {
5151

5252
}
5353

54+
/* [[[ cc_cut */
5455
void connected_components(graph *g) {
5556
int c; /* component number */
5657
int i; /* counter */
@@ -67,6 +68,7 @@ void connected_components(graph *g) {
6768
}
6869
}
6970
}
71+
/* ]]] */
7072

7173
int main(void) {
7274
graph g;

dijkstra.c

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ int parent[MAXV+1]; /* discovery relation */
3838

3939
/* WAS prim(g,start) */
4040

41+
/* [[[ dijkstra_cut */
4142
void dijkstra(graph *g, int start) {
4243
int i; /* counter */
4344
edgenode *p; /* temporary pointer */
@@ -80,6 +81,7 @@ void dijkstra(graph *g, int start) {
8081
}
8182
}
8283
}
84+
/* ]]] */
8385

8486
int main(void) {
8587
graph g;

editbrute.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ This book can be ordered from Amazon.com at
3030

3131
#include "editdistance.h"
3232

33+
/* [[[ cell_instance_cut */
3334
cell m[MAXLEN+1][MAXLEN+1]; /* dynamic programming table */
34-
35+
/* ]]] */
3536

3637
/**********************************************************************/
3738
void goal_cell(char *s, char *t, int *i, int *j) {
@@ -86,6 +87,7 @@ void delete_out(char *s, int i) {
8687
printf("D");
8788
}
8889

90+
/* [[[ string_compare_cut */
8991
int string_compare2(char *s, char *t, int i, int j, cell m[MAXLEN+1][MAXLEN+1]) {
9092
int k; /* counter */
9193
int opt[3]; /* cost of the three options */
@@ -113,7 +115,8 @@ int string_compare2(char *s, char *t, int i, int j, cell m[MAXLEN+1][MAXLEN+1])
113115
m[i][j].cost = lowest_cost; /* REMOVE FROM PRINTED VERSION */
114116

115117
return(lowest_cost);
116-
}
118+
}
119+
/* ]]] */
117120

118121
void reconstruct_path(char *s, char *t, int i, int j, cell m[MAXLEN+1][MAXLEN+1]) {
119122
if (m[i][j].parent == -1) {

editdistance.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This book can be ordered from Amazon.com at
3232
#include "editdistance.h"
3333

3434
/**********************************************************************/
35-
35+
/* [[[ editdistance_str_compare_cut */
3636
int string_compare(char *s, char *t, cell m[MAXLEN+1][MAXLEN+1]) {
3737
int i, j, k; /* counters */
3838
int opt[3]; /* cost of the three options */
@@ -61,8 +61,10 @@ int string_compare(char *s, char *t, cell m[MAXLEN+1][MAXLEN+1]) {
6161

6262
goal_cell(s, t, &i, &j);
6363
return(m[i][j].cost);
64-
}
64+
}
65+
/* ]]] */
6566

67+
/* [[[ reconstruct_path_ed_cut */
6668
void reconstruct_path(char *s, char *t, int i, int j, cell m[MAXLEN+1][MAXLEN+1]) {
6769
if (m[i][j].parent == -1) {
6870
return;
@@ -86,6 +88,7 @@ void reconstruct_path(char *s, char *t, int i, int j, cell m[MAXLEN+1][MAXLEN+1]
8688
return;
8789
}
8890
}
91+
/* ]]] */
8992

9093
void print_matrix(char *s, char *t, bool costQ, cell m[MAXLEN+1][MAXLEN+1]) {
9194
int i, j; /* counters */

editdistance.h

+5
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ This book can be ordered from Amazon.com at
2727
#include "bool.h"
2828

2929
#define MAXLEN 101 /* longest possible string */
30+
31+
/* [[[ editdistance_mid_cut */
3032
#define MATCH 0 /* enumerated type symbol for match */
3133
#define INSERT 1 /* enumerated type symbol for insert */
3234
#define DELETE 2 /* enumerated type symbol for delete */
35+
/* ]]] */
3336

37+
/* [[[ editdistance_cell_struct_cut */
3438
typedef struct {
3539
int cost; /* cost of reaching this cell */
3640
int parent; /* parent cell */
3741
} cell;
42+
/* ]]] */
3843

3944
void row_init(int i, cell m[MAXLEN+1][MAXLEN+1]);
4045
void column_init(int i, cell m[MAXLEN+1][MAXLEN+1]);

0 commit comments

Comments
 (0)