The example shows how to inspect a model.
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct model_buffer {
size_t symbols_n;
char *string;
size_t string_n;
} model_buffer_t;
void free_model_buffer(model_buffer_t *buf) {
if (buf->symbols) {
free(buf->symbols);
buf->symbols = NULL;
buf->symbols_n = 0;
}
if (buf->string) {
free(buf->string);
buf->string = NULL;
buf->string_n = 0;
}
}
bool ret = true;
char *string;
size_t n;
if (buf->string_n < n) {
if (!(string = (char*)realloc(buf->string, sizeof(*buf->string) * n))) {
goto error;
}
buf->string = string;
buf->string_n = n;
}
printf("%s", buf->string);
goto out;
error:
ret = false;
out:
return ret;
}
bool ret = true;
size_t n;
if (buf->symbols_n < n) {
goto error;
}
buf->symbols = symbols;
buf->symbols_n = n;
}
printf("%s:", label);
for (it = buf->symbols, ie = buf->symbols + n; it != ie; ++it) {
printf(" ");
if (!print_symbol(*it, buf)) { goto error; }
}
printf("\n");
goto out;
error:
ret = false;
out:
return ret;
}
bool print_solution(
clingo_model_t const *model, model_buffer_t *data) {
bool ret = true;
uint64_t number;
char const *type_string = "";
}
printf("%s %" PRIu64 ":\n", type_string, number);
goto out;
error:
ret = false;
out:
return ret;
}
bool ret = true;
while (true) {
if (model) { print_solution(model, data); }
else { break; }
}
goto out;
error:
ret = false;
out:
}
int main(int argc, char const **argv) {
char const *error_message;
int ret = 0;
model_buffer_t buf = {NULL, 0, NULL, 0};
if (!
clingo_control_add(ctl,
"base", NULL, 0,
"1 {a; b} 1. #show c : b. #show a/0.")) {
goto error; }
if (!solve(ctl, &buf, &solve_ret)) { goto error; }
goto out;
error:
printf("%s\n", error_message);
out:
free_model_buffer(&buf);
return ret;
}