Exemplo n.º 1
0
StochGenMatrix* sTreeImpl::createC() 
{
  //is this node a dead-end for this process?
  if(commWrkrs==MPI_COMM_NULL)
    return new StochGenDummyMatrix(m_id);

  StochGenMatrix* C = NULL;
  if (m_id==0) {
    CoinPackedMatrix Crow; 
    Crow.reverseOrderedCopyOf( in.getFirstStageConstraints() );

    // number of nz in the rows corresponding to ineq constraints
    int nnzD=countNNZ( Crow, 
		       in.getFirstStageRowLB(), 
		       in.getFirstStageRowUB(), 
		       ineq_comp());
    C = new StochGenMatrix( m_id, MZ, N, 
			    m_mz, 0,   0,    // C does not exist for the root
			    m_mz, m_nx, nnzD, // D is 1st stage ineq matrix
			    commWrkrs );
    extractRows( Crow,
		 in.getFirstStageRowLB(), in.getFirstStageRowUB(), ineq_comp(),
		 C->Bmat->krowM(), C->Bmat->jcolM(), C->Bmat->M() );
    //printf("  -- 1st stage mz=%lu nx=%lu nnzD=%d\n", m_mz, m_nx, nnzD);
  } else {
    int scen=m_id-1;
    CoinPackedMatrix Crow, Drow; 
    Crow.reverseOrderedCopyOf( in.getLinkingConstraints(scen) );
    Drow.reverseOrderedCopyOf( in.getSecondStageConstraints(scen) );

    int nnzC=countNNZ( Crow, in.getSecondStageRowLB(scen), 
		       in.getSecondStageRowUB(scen), ineq_comp() );
    int nnzD=countNNZ( Drow, in.getSecondStageRowLB(scen), 
		       in.getSecondStageRowUB(scen), ineq_comp() );

    C = new StochGenMatrix( m_id, MZ, N, 
			    m_mz, parent->m_nx, nnzC, 
			    m_mz, m_nx,         nnzD,
			    commWrkrs );
    //printf("  -- 2nd stage mz=%lu nx=%lu   1st stage nx=%lu     nnzC=%d nnzD=%d\n", m_mz, m_nx, parent->m_nx, nnzC, nnzD);
    extractRows( Crow,
		 in.getSecondStageRowLB(scen), 
		 in.getSecondStageRowUB(scen), 
		 ineq_comp(),
		 C->Amat->krowM(), C->Amat->jcolM(), C->Amat->M() );
    extractRows( Drow,
		 in.getSecondStageRowLB(scen), 
		 in.getSecondStageRowUB(scen), 
		 ineq_comp(),
		 C->Bmat->krowM(), C->Bmat->jcolM(), C->Bmat->M() );
  }
  
  for(size_t it=0; it<children.size(); it++) {
    StochGenMatrix* child = ((sTreeImpl*)children[it])->createC();
    C->AddChild(child);
  }
  return C;
}
Exemplo n.º 2
0
void write_sparsebin(int nr, int nc, int **x, char *fname) //
{
	int i, j, k, chk;
	int NNZ   = countNNZ(nr,nc,x);
	int *col1 = ivec(NNZ);
	int *col2 = ivec(NNZ);
	int *col3 = ivec(NNZ);
	FILE *fp  = fopen(fname,"w"); assert(fp);
	for (i = 0, k = 0; i < nr; i++) 
		for (j = 0; j < nc; j++) 
			if (x[i][j] > 0) {
				col1[k] = i;
				col2[k] = j;
				col3[k] = x[i][j];
				k++;
			}
			assert(k==NNZ);
			fwrite(&nr, sizeof(int),1,fp);
			fwrite(&nc, sizeof(int),1,fp);
			fwrite(&NNZ,sizeof(int),1,fp);
			chk = fwrite(col1,sizeof(int),NNZ,fp); assert(chk==NNZ);
			chk = fwrite(col2,sizeof(int),NNZ,fp); assert(chk==NNZ);
			chk = fwrite(col3,sizeof(int),NNZ,fp); assert(chk==NNZ);
			fclose(fp);
			free(col1);
			free(col2);
			free(col3);
}
Exemplo n.º 3
0
void write_sparse(int nr, int nc, int **x, char *fname) //
{
	FILE *fp = fopen(fname,"w");
	int i, j;
	assert(fp);
	fprintf(fp, "%d\n", nr);
	fprintf(fp, "%d\n", nc);
	fprintf(fp, "%d\n", countNNZ(nr,nc,x));
	for (i = 0; i < nr; i++) 
		for (j = 0; j < nc; j++) 
			if (x[i][j] > 0) fprintf(fp, "%d %d %d\n", i+1 , j+1 , x[i][j]);
	fclose(fp);
}
Exemplo n.º 4
0
StochGenMatrix* sTreeImpl::createA() 
{
  //is this node a dead-end for this process?
  if(commWrkrs==MPI_COMM_NULL)
    return new StochGenDummyMatrix(m_id);

  StochGenMatrix* A = NULL;
  if (m_id==0) {
    CoinPackedMatrix Arow; 
    Arow.reverseOrderedCopyOf( in.getFirstStageConstraints() );
    assert(false==Arow.hasGaps());  

    // number of nz in the rows corresponding to eq constraints
    int nnzB=countNNZ( Arow, 
		       in.getFirstStageRowLB(), 
		       in.getFirstStageRowUB(), 
		       eq_comp());
    //printf("%d  -- 1st stage my=%lu nx=%lu nnzB=%d\n", commie, m_my, m_nx, nnzB);
    A = new StochGenMatrix( m_id, MY, N, 
			    m_my, 0,   0,    // A does not exist for the root
			    m_my, m_nx, nnzB, // B is 1st stage eq matrix
			    commWrkrs );
    extractRows( Arow,
		 in.getFirstStageRowLB(), in.getFirstStageRowUB(), eq_comp(),
		 A->Bmat->krowM(), A->Bmat->jcolM(), A->Bmat->M() );

  } else {
    int scen=m_id-1;
    CoinPackedMatrix Arow, Brow; 
    Arow.reverseOrderedCopyOf( in.getLinkingConstraints(scen) );
    Brow.reverseOrderedCopyOf( in.getSecondStageConstraints(scen) );

    int nnzA=countNNZ( Arow, in.getSecondStageRowLB(scen), 
		       in.getSecondStageRowUB(scen), eq_comp() );
    int nnzB=countNNZ( Brow, in.getSecondStageRowLB(scen), 
		       in.getSecondStageRowUB(scen), eq_comp() );

    A = new StochGenMatrix( m_id, MY, N, 
			    m_my, parent->m_nx, nnzA, 
			    m_my, m_nx,         nnzB,
			    commWrkrs );
    //cout << commie << "  -- 2nd stage my=" << m_my << " nx=" << m_nx 
    // << "  1st stage nx=" << parent->m_nx << "  nnzA=" << nnzA << " nnzB=" << nnzB << endl;
    extractRows( Arow,
		 in.getSecondStageRowLB(scen), 
		 in.getSecondStageRowUB(scen), 
		 eq_comp(),
		 A->Amat->krowM(), A->Amat->jcolM(), A->Amat->M() );
    extractRows( Brow,
		 in.getSecondStageRowLB(scen), 
		 in.getSecondStageRowUB(scen), 
		 eq_comp(),
		 A->Bmat->krowM(), A->Bmat->jcolM(), A->Bmat->M() );
  }
  
  for(size_t it=0; it<children.size(); it++) {
    StochGenMatrix* child = ((sTreeImpl*)children[it])->createA();
    A->AddChild(child);
  }
  return A;
}