+
+
+ /*
+ * Capacity constraint block.
+ */
+ xbt_swag_foreach(cnst, cnst_list) {
+
+ fprintf(sdpout,"0 %d 1 1 %d\n", block_num, (int) - (cnst->bound));
+ addentry(constraints, &C, 0, block_num, 1, 1, - (cnst->bound) , C.blocks[block_num].blocksize);
+
+ elem_list = &(cnst->element_set);
+ xbt_swag_foreach(elem, elem_list) {
+ if(elem->variable->weight <=0) break;
+ fprintf(sdpout,"%d %d 1 1 %d\n", elem->variable->index, block_num, (int) - (elem->variable->value));
+ addentry(constraints, &C, elem->variable->index, block_num, 1, 1, - (elem->value), C.blocks[block_num].blocksize);
+ }
+ }
+
+
+ //Positivy constraint blocks
+ for(i = 1; i <= pow(2,K); i++){
+ matno=get_y(K, i);
+ fprintf(sdpout,"%d %d 1 1 1\n", matno, block_num);
+ addentry(constraints, &C, matno, block_num, 1, 1, 1.0, C.blocks[block_num].blocksize);
+ block_num++;
+ }
+
+
+ /*
+ * At this point, we'll stop to recognize whether any of the blocks
+ * are "hidden LP blocks" and correct the block type if needed.
+ */
+ for (i=1; i<=nb_cnsts; i++){
+ if ((C.blocks[i].blockcategory != DIAG) &&
+ (isdiag[i]==1) && (C.blocks[i].blocksize > 1)){
+ /*
+ * We have a hidden diagonal block!
+ */
+
+ printf("Block %d is actually diagonal.\n",i);
+
+ blocksz=C.blocks[i].blocksize;
+ tempdiag=(double *)calloc((blocksz+1), sizeof(double));
+ for (j=1; j<=blocksz; j++)
+ tempdiag[j]=C.blocks[i].data.mat[ijtok(j,j,blocksz)];
+ free(C.blocks[i].data.mat);
+ C.blocks[i].data.vec=tempdiag;
+ C.blocks[i].blockcategory=DIAG;
+ };
+ };
+
+
+ /*
+ * Next, setup issparse and NULL out all nextbyblock pointers.
+ */
+ struct sparseblock *p=NULL;
+ for (i=1; i<=k; i++) {
+ p=constraints[i].blocks;
+ while (p != NULL){
+ /*
+ * First, set issparse.
+ */
+ if (((p->numentries) > 0.25*(p->blocksize)) && ((p->numentries) > 15)){
+ p->issparse=0;
+ }else{
+ p->issparse=1;
+ };
+
+ if (C.blocks[p->blocknum].blockcategory == DIAG)
+ p->issparse=1;
+
+ /*
+ * Setup the cross links.
+ */
+
+ p->nextbyblock=NULL;
+ p=p->next;
+ };
+ };
+
+
+ /*
+ * Create cross link reference.
+ */
+ create_cross_link(constraints, nb_var);
+
+
+ /*
+ * Debuging print problem in SDPA format.
+ */
+ printf("Printing SDPA...\n");
+ if(XBT_LOG_ISENABLED(surf_sdp, xbt_log_priority_debug)) {
+ char *tmp=strdup("SDPA.tmp");
+ write_prob(tmp, nb_cnsts, nb_var, C, a, constraints);
+ //int write_prob(char *fname, int n, int k, struct blockmatrix C, double *a, struct constraintmatrix *constraints);
+ free(tmp);
+ }
+
+ /*
+ * Initialize parameters.
+ */
+ printf("Initializing solution...\n");
+ initsoln(nb_cnsts, nb_var, C, a, constraints, &X, &y, &Z);