Beispiel #1
0
void CONSTR_FIX_allocate(Constr* c) {

  // Local variables
  int num_constr;
  int num_vars;
  int A_nnz;

  // Constr data
  num_vars = NET_get_num_vars(CONSTR_get_network(c));
  num_constr = CONSTR_get_A_row(c);
  A_nnz = CONSTR_get_A_nnz(c);

  // J f
  CONSTR_set_J(c,MAT_new(0,num_vars,0));
  CONSTR_set_f(c,VEC_new(0));

  // G l u
  CONSTR_set_G(c,MAT_new(0,num_vars,0));
  CONSTR_set_l(c,VEC_new(0));
  CONSTR_set_u(c,VEC_new(0));

  // b
  CONSTR_set_b(c,VEC_new(num_constr));

  // A
  CONSTR_set_A(c,MAT_new(num_constr, // size1 (rows)
			 num_vars,   // size2 (cols)
			 A_nnz)); // nnz
}
Beispiel #2
0
void CONSTR_LOAD_PF_allocate(Constr* c) {

  // Local variables
  int num_constr;
  int num_vars;
  int A_nnz;

  num_vars = NET_get_num_vars(CONSTR_get_network(c));
  num_constr = CONSTR_get_A_row(c);
  A_nnz = CONSTR_get_A_nnz(c);

  // J f
  CONSTR_set_J(c,MAT_new(0,num_vars,0));
  CONSTR_set_f(c,VEC_new(0));

  // A b
  CONSTR_set_A(c,MAT_new(num_constr, // rows
			 num_vars,   // cols
			 A_nnz));    // nnz
  CONSTR_set_b(c,VEC_new(num_constr));

  // G l u
  CONSTR_set_l(c,VEC_new(0));
  CONSTR_set_u(c,VEC_new(0));
  CONSTR_set_G(c,MAT_new(0,        // rows
			 num_vars, // cols
			 0));      // nnz
}
Beispiel #3
0
void CONSTR_DC_FLOW_LIM_allocate(Constr* c) {
  
  // Local variables
  Net* net;
  int num_br;
  int num_vars;
  int Gcounter;

  net = CONSTR_get_network(c);
  num_br = NET_get_num_branches(net);
  num_vars = NET_get_num_vars(net);
  Gcounter = CONSTR_get_Gcounter(c);
  
  // J f
  CONSTR_set_J(c,MAT_new(0,num_vars,0));
  CONSTR_set_f(c,VEC_new(0));
  
  // A b
  CONSTR_set_A(c,MAT_new(0,num_vars,0));
  CONSTR_set_b(c,VEC_new(0));
  
  // h
  CONSTR_set_l(c,VEC_new(num_br));
  CONSTR_set_u(c,VEC_new(num_br));

  // G
  CONSTR_set_G(c,MAT_new(num_br,      // size1 (rows)
			 num_vars,    // size2 (cols)
			 Gcounter));  // nnz
}
Beispiel #4
0
void CONSTR_BOUND_allocate(Constr* c) {

  // Local variables
  int Jcounter;
  Mat* H_array;
  Mat* H;
  int num_vars;
  int i;
  
  Jcounter = CONSTR_get_Jcounter(c);
  num_vars = NET_get_num_vars(CONSTR_get_network(c));

  // A b
  CONSTR_set_A(c,MAT_new(0,num_vars,0));
  CONSTR_set_b(c,VEC_new(0));
  
  // f
  CONSTR_set_f(c,VEC_new(Jcounter));

  // J
  CONSTR_set_J(c,MAT_new(Jcounter,   // size1 (rows)
			 num_vars,   // size2 (cols)
			 Jcounter)); // nnz
  
  // H
  H_array = MAT_array_new(Jcounter);
  CONSTR_set_H_array(c,H_array,Jcounter);
  for (i = 0; i < Jcounter; i++) {
    H = MAT_array_get(H_array,i);
    MAT_set_nnz(H,1);
    MAT_set_size1(H,num_vars);
    MAT_set_size2(H,num_vars);
    MAT_set_row_array(H,(int*)calloc(1,sizeof(int)));
    MAT_set_col_array(H,(int*)calloc(1,sizeof(int)));
    MAT_set_data_array(H,(REAL*)malloc(1*sizeof(REAL)));
  }

  // H combined
  CONSTR_set_H_combined(c,MAT_new(num_vars,   // size1 (rows)
				  num_vars,   // size2 (cols)
				  Jcounter)); // nnz
}
Beispiel #5
0
void CONSTR_PAR_GEN_Q_allocate(Constr *c) {
  
  // Local variables
  int num_constr;
  int num_vars;
  int Acounter;
  
  num_vars = NET_get_num_vars(CONSTR_get_network(c));
  num_constr = CONSTR_get_Aconstr_index(c);
  Acounter = CONSTR_get_Acounter(c);

  // J f
  CONSTR_set_J(c,MAT_new(0,num_vars,0));
  CONSTR_set_f(c,VEC_new(0));

  // b
  CONSTR_set_b(c,VEC_new(num_constr));

  // A
  CONSTR_set_A(c,MAT_new(num_constr, // size1 (rows)
			 num_vars,   // size2 (rows)
			 Acounter)); // nnz
}
Beispiel #6
0
void CONSTR_BOUND_analyze_step(Constr* c, Branch* br, int t) {

  // Local variables
  Bus* buses[2];
  Bus* bus;
  Gen* gen;
  Shunt* shunt;
  Mat* J;
  Mat* H_array;
  Mat* H;
  int* Hi;
  int* Hj;
  int* Hi_comb;
  int* Hj_comb;
  int* Jcounter;
  char* bus_counted;
  int bus_index_t[2];
  int index_var;
  int k;
  int T;

  // Number of periods
  T = BRANCH_get_num_periods(br);

  // Constr data
  J = CONSTR_get_J(c);
  H_array = CONSTR_get_H_array(c);
  Jcounter = CONSTR_get_Jcounter_ptr(c);
  bus_counted = CONSTR_get_bus_counted(c);

  // Check pointers
  if (!Jcounter || !bus_counted)
    return;

  // Check outage
  if (BRANCH_is_on_outage(br))
    return;

  // Bus data
  buses[0] = BRANCH_get_bus_from(br);
  buses[1] = BRANCH_get_bus_to(br);
  for (k = 0; k < 2; k++)
    bus_index_t[k] = BUS_get_index(buses[k])*T+t;

  // Branch
  //*******

  // Tap ratio
  if (BRANCH_has_flags(br,FLAG_BOUNDED,BRANCH_VAR_RATIO) && 
      BRANCH_has_flags(br,FLAG_VARS,BRANCH_VAR_RATIO)) {

    index_var = BRANCH_get_index_ratio(br,t);
    
    // J
    MAT_set_i(J,*Jcounter,*Jcounter);
    MAT_set_j(J,*Jcounter,index_var);

    MAT_set_i(J,*Jcounter+1,*Jcounter+1);
    MAT_set_j(J,*Jcounter+1,index_var);

    // H
    H = MAT_array_get(H_array,*Jcounter);
    MAT_set_i(H,0,index_var);
    MAT_set_j(H,0,index_var);

    H = MAT_array_get(H_array,*Jcounter+1);
    MAT_set_i(H,0,index_var);
    MAT_set_j(H,0,index_var);

    (*Jcounter)++;
    (*Jcounter)++;
  }

  // Phase shift
  if (BRANCH_has_flags(br,FLAG_BOUNDED,BRANCH_VAR_PHASE) && 
      BRANCH_has_flags(br,FLAG_VARS,BRANCH_VAR_PHASE)) {

    index_var = BRANCH_get_index_phase(br,t);

    // J
    MAT_set_i(J,*Jcounter,*Jcounter);
    MAT_set_j(J,*Jcounter,index_var);

    MAT_set_i(J,*Jcounter+1,*Jcounter+1);
    MAT_set_j(J,*Jcounter+1,index_var);

    // H
    H = MAT_array_get(H_array,*Jcounter);
    MAT_set_i(H,0,index_var);
    MAT_set_j(H,0,index_var);

    H = MAT_array_get(H_array,*Jcounter+1);
    MAT_set_i(H,0,index_var);
    MAT_set_j(H,0,index_var);
    
    (*Jcounter)++;
    (*Jcounter)++;
  }
  
  // Buses
  //******

  for (k = 0; k < 2; k++) {

    bus = buses[k];

    if (!bus_counted[bus_index_t[k]]) { // not counted yet
      
      // Voltage magnitude (V_MAG)
      if (BUS_has_flags(bus,FLAG_BOUNDED,BUS_VAR_VMAG) && BUS_has_flags(bus,FLAG_VARS,BUS_VAR_VMAG)) {

	index_var = BUS_get_index_v_mag(bus,t);

	// J
	MAT_set_i(J,*Jcounter,*Jcounter);
	MAT_set_j(J,*Jcounter,index_var);

	MAT_set_i(J,*Jcounter+1,*Jcounter+1);
	MAT_set_j(J,*Jcounter+1,index_var);
	
	// H
	H = MAT_array_get(H_array,*Jcounter);
	MAT_set_i(H,0,index_var);
	MAT_set_j(H,0,index_var);

	H = MAT_array_get(H_array,*Jcounter+1);
	MAT_set_i(H,0,index_var);
	MAT_set_j(H,0,index_var);
	
	(*Jcounter)++;
	(*Jcounter)++;
      }

      // Volage angle (V_ANG)
      if (BUS_has_flags(bus,FLAG_BOUNDED,BUS_VAR_VANG) && BUS_has_flags(bus,FLAG_VARS,BUS_VAR_VANG)) {

	index_var = BUS_get_index_v_ang(bus,t);

	// J
	MAT_set_i(J,*Jcounter,*Jcounter);
	MAT_set_j(J,*Jcounter,index_var);

	MAT_set_i(J,*Jcounter+1,*Jcounter+1);
	MAT_set_j(J,*Jcounter+1,index_var);
	
	// H
	H = MAT_array_get(H_array,*Jcounter);
	MAT_set_i(H,0,index_var);
	MAT_set_j(H,0,index_var);

	H = MAT_array_get(H_array,*Jcounter+1);
	MAT_set_i(H,0,index_var);
	MAT_set_j(H,0,index_var);
	
	(*Jcounter)++;
	(*Jcounter)++;
      }

      // Generators
      for (gen = BUS_get_gen(bus); gen != NULL; gen = GEN_get_next(gen)) {
	
	// Active power (P)
	if (GEN_has_flags(gen,FLAG_BOUNDED,GEN_VAR_P) && 
	    GEN_has_flags(gen,FLAG_VARS,GEN_VAR_P)) {

	  index_var = GEN_get_index_P(gen,t);
	  
	  // J
	  MAT_set_i(J,*Jcounter,*Jcounter);
	  MAT_set_j(J,*Jcounter,index_var);

	  MAT_set_i(J,*Jcounter+1,*Jcounter+1);
	  MAT_set_j(J,*Jcounter+1,index_var);
	  
	  // H
	  H = MAT_array_get(H_array,*Jcounter);
	  MAT_set_i(H,0,index_var);
	  MAT_set_j(H,0,index_var);

	  H = MAT_array_get(H_array,*Jcounter+1);
	  MAT_set_i(H,0,index_var);
	  MAT_set_j(H,0,index_var);
	  
	  (*Jcounter)++;
	  (*Jcounter)++;
	}
	
	// Reactive power (Q)
	if (GEN_has_flags(gen,FLAG_BOUNDED,GEN_VAR_Q) && 
	    GEN_has_flags(gen,FLAG_VARS,GEN_VAR_Q)) {

	  index_var = GEN_get_index_Q(gen,t);
	  
	  // J
	  MAT_set_i(J,*Jcounter,*Jcounter);
	  MAT_set_j(J,*Jcounter,index_var);

	  MAT_set_i(J,*Jcounter+1,*Jcounter+1);
	  MAT_set_j(J,*Jcounter+1,index_var);
	  
	  // H
	  H = MAT_array_get(H_array,*Jcounter);
	  MAT_set_i(H,0,index_var);
	  MAT_set_j(H,0,index_var);

	  H = MAT_array_get(H_array,*Jcounter+1);
	  MAT_set_i(H,0,index_var);
	  MAT_set_j(H,0,index_var);
	  
	  (*Jcounter)++;
	  (*Jcounter)++;
	}
      }

      // Shunts
      for (shunt = BUS_get_shunt(bus); shunt != NULL; shunt = SHUNT_get_next(shunt)) {
		
	// Susceptance
	if (SHUNT_has_flags(shunt,FLAG_BOUNDED,SHUNT_VAR_SUSC) && 
	    SHUNT_has_flags(shunt,FLAG_VARS,SHUNT_VAR_SUSC)) {
	  
	  index_var = SHUNT_get_index_b(shunt,t);
	  
	  // J
	  MAT_set_i(J,*Jcounter,*Jcounter);
	  MAT_set_j(J,*Jcounter,index_var);

	  MAT_set_i(J,*Jcounter+1,*Jcounter+1);
	  MAT_set_j(J,*Jcounter+1,index_var);
	  
	  // H
	  H = MAT_array_get(H_array,*Jcounter);
	  MAT_set_i(H,0,index_var);
	  MAT_set_j(H,0,index_var);

	  H = MAT_array_get(H_array,*Jcounter+1);
	  MAT_set_i(H,0,index_var);
	  MAT_set_j(H,0,index_var);
	  
	  (*Jcounter)++;
	  (*Jcounter)++;
	}
      }
    }	  
    
    // Update counted flag
    bus_counted[bus_index_t[k]] = TRUE;
  }

  // Done (last branch and period)
  if ((t == T-1) && (BRANCH_get_index(br) == NET_get_num_branches(CONSTR_get_network(c))-1)) {
    
    // Ensure lower triangular and save struct of H comb
    Hi_comb = MAT_get_row_array(CONSTR_get_H_combined(c));
    Hj_comb = MAT_get_col_array(CONSTR_get_H_combined(c));
    for (k = 0; k < CONSTR_get_H_array_size(c); k++) {
      Hi = MAT_get_row_array(MAT_array_get(H_array,k));
      Hj = MAT_get_col_array(MAT_array_get(H_array,k));
      Hi_comb[k] = Hi[0];
      Hj_comb[k] = Hj[0];
    }
  }
}