-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadmm_solver.cpp
46 lines (36 loc) · 994 Bytes
/
admm_solver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <armadillo>
using namespace std;
using namespace arma;
// Empty constructor
ADMM_solver::ADMM_solver(){}
// Constructor: receives N, steps, and vector of agents as input
ADMM_solver::ADMM_solver(unsigned _N, unsigned _steps, unsigned _states, std::vector<Agent> _agents){
N = _N;
steps = _steps;
states = _states;
for(int i = 0; i< N; i++){
agents.push_back(_agents[i]);
}
}
// Destructor
ADMM_solver::~ADMM_solver(){}
void ADMM_solver::ADMM_algorithm(){
/*
At each timestep:
Aggregates agent contributions to the global variable update;
Tells agents to compute one iteration of updates to their local variables.
*/
for(int t = 0; t< steps; t++){
std::cout << "Executing time step " << t << ".\n";
vec z = zeros<vec>(states);
for(int current = 0; current < N; current++){
z += agents[current].getValueOfz();
}
z /= N;
z.print("Global z:");
for(int current = 0; current < N; current++){
agents[current].setValueOfz(z);
}
}
}