// CRS ----------------------- int librlc_crs_encode(int k, int m, int w, int packet_size, const char *orig_data, int orig_data_len, char **encoded_data, char **encoded_parity, int *chunk_len) { crs_coder_t crs_code; // crs init crs_init(&crs_code, k+m, k, w, packet_size); // rs encode crs_encode(crs_code.pcrsi, orig_data, orig_data_len, encoded_data, encoded_parity, chunk_len); // rs free crs_free(&crs_code); return 0; }
int librlc_crs_repair(int k, int m, int w, int packet_size, char *available_data, int *data_list, int data_num,int chunk_len, int *repair_list, int repair_num, char **out_data) { int ret = 0; crs_coder_t crs_code; //crs init crs_init(&crs_code, k+m, k, w, packet_size); // re repair ret = crs_repair(crs_code.pcrsi, available_data, data_list, data_num, chunk_len, repair_list, repair_num, out_data); // crs free crs_free(&crs_code); return ret; }
nlopt_result crs_minimize(int n, nlopt_func f, void *f_data, const double *lb, const double *ub, /* bounds */ double *x, /* in: initial guess, out: minimizer */ double *minf, nlopt_stopping *stop, int population, /* initial population (0=default) */ int lds) /* random or low-discrepancy seq. (lds) */ { nlopt_result ret; crs_data d; rb_node *best; ret = crs_init(&d, n, x, lb, ub, stop, f, f_data, population, lds); if (ret < 0) return ret; best = rb_tree_min(&d.t); *minf = best->k[0]; memcpy(x, best->k + 1, sizeof(double) * n); while (ret == NLOPT_SUCCESS) { if (NLOPT_SUCCESS == (ret = crs_trial(&d))) { best = rb_tree_min(&d.t); if (best->k[0] < *minf) { if (best->k[0] < stop->minf_max) ret = NLOPT_MINF_MAX_REACHED; else if (nlopt_stop_f(stop, best->k[0], *minf)) ret = NLOPT_FTOL_REACHED; else if (nlopt_stop_x(stop, best->k + 1, x)) ret = NLOPT_XTOL_REACHED; *minf = best->k[0]; memcpy(x, best->k + 1, sizeof(double) * n); } if (ret != NLOPT_SUCCESS) { if (nlopt_stop_evals(stop)) ret = NLOPT_MAXEVAL_REACHED; else if (nlopt_stop_time(stop)) ret = NLOPT_MAXTIME_REACHED; } } } crs_destroy(&d); return ret; }