static int handle_fork_point(int argc, const char **argv) { struct object_id oid; char *refname; struct commit *derived, *fork_point; const char *commitname; switch (dwim_ref(argv[0], strlen(argv[0]), &oid, &refname)) { case 0: die("No such ref: '%s'", argv[0]); case 1: break; /* good */ default: die("Ambiguous refname: '%s'", argv[0]); } commitname = (argc == 2) ? argv[1] : "HEAD"; if (get_oid(commitname, &oid)) die("Not a valid object name: '%s'", commitname); derived = lookup_commit_reference(the_repository, &oid); fork_point = get_fork_point(refname, derived); if (!fork_point) return 1; printf("%s\n", oid_to_hex(&fork_point->object.oid)); return 0; }
ih_core_bool_t score_solution(void *context, ih_core_bitarray_t *solution, double *score) { assert(score); assert(solution); assert(score); ih_core_bool_t visited[MAX_POINTS]; unsigned short i; unsigned bit_0; unsigned bit_1; unsigned short fork; unsigned short current_point; unsigned short next_point; double distance; stravel_t *stravel; stravel = context; *score = 0.0; for (i = 0; i < stravel->point_count; i++) { visited[i] = ih_core_bool_false; } current_point = 0; visited[0] = ih_core_bool_true; for (i = 0; i < (stravel->point_count - 1); i++) { bit_0 = ih_core_bitarray_get_bit(solution, (current_point * 2) + 0); bit_1 = ih_core_bitarray_get_bit(solution, (current_point * 2) + 1); fork = (bit_0 * 1) + (bit_1 * 2); next_point = get_fork_point(stravel, current_point, fork, visited); visited[next_point] = ih_core_bool_true; distance = get_point_distance_from_cache(stravel, current_point, next_point); *score += distance; current_point = next_point; } return ih_core_bool_true; }
ih_core_bool_t save_solution_to_file(stravel_t *stravel, ih_core_bitarray_t *solution, char *filename) { assert(stravel); assert(filename); ih_core_bool_t visited[MAX_POINTS]; unsigned short each_point; unsigned char bit_0; unsigned char bit_1; unsigned short fork; unsigned short current_point; unsigned short next_point; ih_file_basic_t *file; ih_core_bool_t success; double x; double y; char string[64]; for (each_point = 0; each_point < stravel->point_count; each_point++) { visited[each_point] = ih_core_bool_false; } file = ih_file_basic_create(filename, IH_FILE_MODE_TRUNCATE_OR_CREATE_FOR_WRITE); if (file) { success = ih_core_bool_true; if (!ih_file_basic_write_string(file, "x,y\n")) { success = ih_core_bool_false; ih_audit_log_trace(stravel->log, "stvl", "ih_file_basic_write_string"); } current_point = 0; x = stravel->points[current_point][0]; y = stravel->points[current_point][1]; if (sprintf(string, "%.5f,%.5f\n", x, y) >= 0) { /* TODO */ if (!ih_file_basic_write_string(file, string)) { success = ih_core_bool_false; ih_audit_log_trace(stravel->log, "stvl", "ih_file_basic_write_string"); } } else { success = ih_core_bool_false; ih_audit_log_trace(stravel->log, "stvl", "sprintf"); } visited[current_point] = ih_core_bool_true; for (each_point = 0; each_point < (stravel->point_count - 1); each_point++) { bit_0 = ih_core_bitarray_get_bit(solution, (current_point * 2) + 0); bit_1 = ih_core_bitarray_get_bit(solution, (current_point * 2) + 1); fork = (bit_0 * 1) + (bit_1 * 2); next_point = get_fork_point(stravel, current_point, fork, visited); x = stravel->points[next_point][0]; y = stravel->points[next_point][1]; if (sprintf(string, "%.5f,%.5f\n", x, y) >= 0) { /* TODO */ if (!ih_file_basic_write_string(file, string)) { success = ih_core_bool_false; ih_audit_log_trace(stravel->log, "stvl", "ih_file_basic_write_string"); break; } } else { success = ih_core_bool_false; ih_audit_log_trace(stravel->log, "stvl", "sprintf"); break; } visited[next_point] = ih_core_bool_true; current_point = next_point; } ih_file_basic_destroy(file); } else { success = ih_core_bool_false; ih_audit_log_trace(stravel->log, "stvl", "ih_file_basic_create"); } return success; }