"#define Gt(a, b) Lt(b, a)\n"
"#define Band(v, lo, hi) Lt(lo, v) + Lt(v, hi)\n";
+/**
+ * Read file contents into a string.
+ * !!! WARNING !!!
+ * The pointer this function returns should
+ * be freed before it leaves scope.
+ *
+ * @param f FILE* to read off of.
+ * @return string, stored on heap.
+ */
char *readfile(FILE *f) {
if (f == NULL) return NULL;
int c;
return str;
}
+/**
+ * Read stream (fd) contents into string.
+ * !!! WARNING !!!
+ * The pointer this function returns should
+ * be freed before it leaves scope.
+ *
+ * @param fd file descriptor to read off of.
+ * @return string, stored on heap.
+ */
char *readstream(int fd) {
int s = 128;
int r;
return buf;
}
+/**
+ * Read netlist from file at `task->netlist_file`, apply
+ * macros and store the netlist in `task->netlist` as a string.
+ * !!! WARNING !!!
+ * `task->netlist` should be freed before `task` leaves scope.
+ *
+ * @param task task definition.
+ */
void load_netlist(task_def *task) {
FILE *netlist = fopen( task->netlist_file, "r");
char *netlist_raw = readfile(netlist);
close(out[0]);
}
+/**
+ * Launch ngspice as a child process and assign pid, pipes to `chp`.
+ *
+ * @param chp child process struct to assign pid, pipes to
+ */
void spawn_ngspice(ngspice_process *chp) {
if (pipe(chp->input) || pipe(chp->output)) {
printf("ngsolve: FATAL EXCEPTION\n pipe creation unsuccessful.");
chp->pid = p;
}
+/**
+ * Calculate fitness of design vector `x` given the specification
+ * in the netlist source. For usage with any cgo algorithm.
+ *
+ * @param x design vector, length matching number of design variables.
+ * @return fitness.
+ */
double fitness(double *x) {
ngspice_process chp;
spawn_ngspice(&chp);
return constraints + fitness;
}
-void optimize(task_def *task) {
+/**
+ * Run optimization task using definition `task`.
+ *
+ * @param task definition to use for execution.
+ */
+void run_task(task_def *task) {
double *sample_range_min = malloc(sizeof(double) * task->dvarc);
double *sample_range_max = malloc(sizeof(double) * task->dvarc);
for (size_t d = 0; d < task->dvarc; d++) {
taskg.dvarc = 2;
taskg.dvars = dvars;
load_netlist(&taskg);
- optimize(&taskg);
+ run_task(&taskg);
return 0;
}