Skip to content

Commit

Permalink
reverting lnc cuts in socp, slight improvement in ising, preparing fo…
Browse files Browse the repository at this point in the history
…r the multi-thread versino
  • Loading branch information
hhijazi committed Jan 19, 2018
1 parent 95ca51d commit d4d1dfd
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 77 deletions.
6 changes: 4 additions & 2 deletions examples/MINLP/Power/ACOPF/ACOPF_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ int main (int argc, char * argv[])
/** Voltage related variables */
var<Real> theta("theta");
var<Real> v("|V|", grid.v_min, grid.v_max);
var<Real> vr("vr");
var<Real> vi("vi");
// var<Real> vr("vr");
// var<Real> vi("vi");
var<Real> vr("vr", grid.v_max);
var<Real> vi("vi", grid.v_max);

if (polar) {
ACOPF.add_var(v.in(grid.nodes));
Expand Down
16 changes: 8 additions & 8 deletions examples/MINLP/Power/SOCOPF/SOCOPF_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,17 @@ int main (int argc, char * argv[])

/* Lifted Nonlinear Cuts */
Constraint LNC1("LNC1");
LNC1 = (grid->v_min.from()+grid->v_max.from())*(grid->v_min.to()+grid->v_max.to())*(sin(0.5*(grid->th_max+grid->th_min))*Im_Wij + cos(0.5*(grid->th_max+grid->th_min))*R_Wij);
LNC1 -= grid->v_max.to()*cos(0.5*(grid->th_max-grid->th_min))*(grid->v_min.to()+grid->v_max.to())*Wii.from();
LNC1 -= grid->v_max.from()*cos(0.5*(grid->th_max-grid->th_min))*(grid->v_min.from()+grid->v_max.from())*Wii.to();
LNC1 -= grid->v_max.from()*grid->v_max.to()*cos(0.5*(grid->th_max-grid->th_min))*(grid->v_min.from()*grid->v_min.to() - grid->v_max.from()*grid->v_max.to());
LNC1 += (grid->v_min.from()+grid->v_max.from())*(grid->v_min.to()+grid->v_max.to())*(grid->sphi*Im_Wij + grid->cphi*R_Wij);
LNC1 -= grid->v_max.to()*grid->cos_d*(grid->v_min.to()+grid->v_max.to())*Wii.from();
LNC1 -= grid->v_max.from()*grid->cos_d*(grid->v_min.from()+grid->v_max.from())*Wii.to();
LNC1 -= grid->v_max.from()*grid->v_max.to()*grid->cos_d*(grid->v_min.from()*grid->v_min.to() - grid->v_max.from()*grid->v_max.to());
SOCP.add_constraint(LNC1.in(bus_pairs) >= 0);

Constraint LNC2("LNC2");
LNC2 = (grid->v_min.from()+grid->v_max.from())*(grid->v_min.to()+grid->v_max.to())*(sin(0.5*(grid->th_max+grid->th_min))*Im_Wij + cos(0.5*(grid->th_max+grid->th_min))*R_Wij);
LNC2 -= grid->v_min.to()*cos(0.5*(grid->th_max-grid->th_min))*(grid->v_min.to()+grid->v_max.to())*Wii.from();
LNC2 -= grid->v_min.from()*cos(0.5*(grid->th_max-grid->th_min))*(grid->v_min.from()+grid->v_max.from())*Wii.to();
LNC2 += grid->v_min.from()*grid->v_min.to()*cos(0.5*(grid->th_max-grid->th_min))*(grid->v_min.from()*grid->v_min.to() - grid->v_max.from()*grid->v_max.to());
LNC2 += (grid->v_min.from()+grid->v_max.from())*(grid->v_min.to()+grid->v_max.to())*(grid->sphi*Im_Wij + grid->cphi*R_Wij);
LNC2 -= grid->v_min.to()*grid->cos_d*(grid->v_min.to()+grid->v_max.to())*Wii.from();
LNC2 -= grid->v_min.from()*grid->cos_d*(grid->v_min.from()+grid->v_max.from())*Wii.to();
LNC2 += grid->v_min.from()*grid->v_min.to()*grid->cos_d*(grid->v_min.from()*grid->v_min.to() - grid->v_max.from()*grid->v_max.to());
SOCP.add_constraint(LNC2.in(bus_pairs) >= 0);


Expand Down
4 changes: 2 additions & 2 deletions examples/NLP/Ising/Ising_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ double sum_x(){

int main (int argc, char * argv[])
{
int output = 0;
int output = 5;
bool relax = false;
string fname = "../data_sets/Ising/samples_bin_med.csv", log_level="0";
string fname = "../data_sets/Ising/samples_bin.csv", log_level="5";
string path = argv[0];
if (path.find("/bin")!=string::npos && path.find("/bin/ising")==string::npos) {//Not running from terminal
fname = "../" + fname;
Expand Down
2 changes: 2 additions & 0 deletions include/gravity/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,8 @@ namespace gravity {
propagate_nb_ind(_nb_instances);
return *this;
}
void eval_matrix();
void eval_vector();

func_& in(const vector<Node*>& vec) {
_nb_vars = 0;
Expand Down
28 changes: 14 additions & 14 deletions include/gravity/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,17 @@ namespace gravity {

type eval(unsigned i) const {
if (_is_indexed) {
if (_ids->size()>1) {
throw invalid_argument("eval() should be called with double index here\n");
}
if (_val->size()<=_ids->at(0).at(i)){
throw invalid_argument("Param eval out of range");
}
// if (_ids->size()>1) {
// throw invalid_argument("eval() should be called with double index here\n");
// }
// if (_val->size()<=_ids->at(0).at(i)){
// throw invalid_argument("Param eval out of range");
// }
return _val->at(_ids->at(0).at(i));
}
if (_val->size()<=i){
throw invalid_argument("Param eval out of range");
}
// if (_val->size()<=i){
// throw invalid_argument("Param eval out of range");
// }
return _val->at(i);
}

Expand All @@ -461,13 +461,13 @@ namespace gravity {
type eval(unsigned i, unsigned j) const {

if (_is_indexed && _ids->size()>1) {
// if (_ids->at(i).at(j) >= _val->size()) {
// throw invalid_argument("eval(i,j): out of range");
// }
// if (_ids->at(i).at(j) >= _val->size()) {
// throw invalid_argument("eval(i,j): out of range");
// }
return _val->at(_ids->at(i).at(j));
}

//
//
if (!_is_matrix) {
return eval(j);
}
Expand Down
Loading

0 comments on commit d4d1dfd

Please sign in to comment.