Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.6 kB
2
Indexable
Never
node_t* extend(node_t* p, int m, int n, double** a, double* b, double* c, int k, double ak, double bk) {
    node_t* q = calloc(1, sizeof(node_t));
    q->k = k;
    q->ak = ak;
    q->bk = bk;
    q->next = NULL;
    if (ak > 0 && p->max[k] < HUGE_VAL) {
        q->m = p->m;
    } else if (ak < 0 && p->min[k] > 0) {
        q->m = p->m;
    } else {
        q->m = p->m + 1;
    }
    q->n = p->n;
    q->h = -1;
    q->a = make_matrix(q->m+1, q->n+1);
    q->b = calloc(q->m+1, sizeof(double));
    q->c = calloc(q->n+1, sizeof(double));
    q->x = calloc(q->n+1, sizeof(double));
    q->min = calloc(n, sizeof(double));
    q->max = calloc(n, sizeof(double));
    int i, j;
    for(i = 0; i < n; i++) {
        q->min[i] = p->min[i];
        q->max[i] = p->max[i];
    }
    for(i = 0; i < m; i++) {
        for(j = 0; j < n + 1; j++) {
            q->a[i][j] = a[i][j];
        }
        q->b[i] = b[i];
    }
    //Eller n + 1? Hur lång är c?
    for(i = 0; i < n+1; i++) {
        q->c[i] = c[i];
    }
    if(ak > 0) {
        if(q->max[k] == INFINITY || bk < q->max[k]) {
            q->max[k] = bk;
        }
    } else if (q->min[k] == -INFINITY ||bk > q->min[k]) {
        q->min[k] = -bk;
    }
    for(i = m, j = 0; j < n; j++) {
        if(q->min[j] > -INFINITY) {
            q->a[i][j] = -1;
            q->b[i] = -q->min[j];
            i++;
        }
        if(q->max[j] < INFINITY) {
            q->a[i][j] = 1;
            q->b[i] = q->max[j];
            i++;
        }
    }
    return q;
}