Commit 8b719a0b authored by Martin Karlsson's avatar Martin Karlsson
Browse files

added plot functions

parent fb43f50d
This diff is collapsed.
/* Produced by CVXGEN, 2016-01-17 08:15:56 -0500. */
/* CVXGEN is Copyright (C) 2006-2012 Jacob Mattingley, jem@cvxgen.com. */
/* The code in this file is Copyright (C) 2006-2012 Jacob Mattingley. */
/* CVXGEN, or solvers produced by CVXGEN, cannot be used for commercial */
/* applications without prior written permission from Jacob Mattingley. */
/* Filename: solver.h. */
/* Description: Header file with relevant definitions. */
#ifndef SOLVER_H
#define SOLVER_H
/* Uncomment the next line to remove all library dependencies. */
/*#define ZERO_LIBRARY_MODE */
#ifdef MATLAB_MEX_FILE
/* Matlab functions. MATLAB_MEX_FILE will be defined by the mex compiler. */
/* If you are not using the mex compiler, this functionality will not intrude, */
/* as it will be completely disabled at compile-time. */
#include "mex.h"
#else
#ifndef ZERO_LIBRARY_MODE
#include <stdio.h>
#endif
#endif
/* Space must be allocated somewhere (testsolver.c, csolve.c or your own */
/* program) for the global variables vars, params, work and settings. */
/* At the bottom of this file, they are externed. */
#ifndef ZERO_LIBRARY_MODE
#include <math.h>
#define pm(A, m, n) printmatrix(#A, A, m, n, 1)
#endif
#include <armadillo>
using namespace arma;
typedef struct Params_t {
double traj1_1[1];
double traj1_2[1];
double traj1_3[1];
double traj1_4[1];
double traj1_5[1];
double traj1_6[1];
double traj1_7[1];
double traj1_8[1];
double traj1_9[1];
double traj1_10[1];
double traj1_11[1];
double traj1_12[1];
double traj1_13[1];
double traj1_14[1];
double traj1_15[1];
double traj1_16[1];
double traj1_17[1];
double traj1_18[1];
double traj1_19[1];
double traj1_20[1];
double traj1_21[1];
double traj1_22[1];
double traj1_23[1];
double traj1_24[1];
double traj1_25[1];
double traj1_26[1];
double traj1_27[1];
double traj1_28[1];
double traj1_29[1];
double traj1_30[1];
double traj1_31[1];
double traj1_32[1];
double traj1_33[1];
double traj1_34[1];
double traj1_35[1];
double traj1_36[1];
double traj1_37[1];
double traj1_38[1];
double traj1_39[1];
double traj1_40[1];
double traj1_41[1];
double traj1_42[1];
double traj1_43[1];
double traj1_44[1];
double traj1_45[1];
double traj1_46[1];
double traj1_47[1];
double traj1_48[1];
double traj1_49[1];
double traj1_50[1];
double traj1_51[1];
double traj1_52[1];
double traj1_53[1];
double traj1_54[1];
double traj1_55[1];
double traj1_56[1];
double traj1_57[1];
double traj1_58[1];
double traj1_59[1];
double traj1_60[1];
double traj1_61[1];
double traj1_62[1];
double traj1_63[1];
double traj1_64[1];
double traj1_65[1];
double traj1_66[1];
double traj1_67[1];
double traj1_68[1];
double traj1_69[1];
double traj1_70[1];
double traj1_71[1];
double traj1_72[1];
double traj1_73[1];
double traj1_74[1];
double traj1_75[1];
double traj1_76[1];
double traj1_77[1];
double traj1_78[1];
double traj1_79[1];
double traj1_80[1];
double traj1_81[1];
double traj1_82[1];
double traj1_83[1];
double traj1_84[1];
double traj1_85[1];
double traj1_86[1];
double traj1_87[1];
double traj1_88[1];
double traj1_89[1];
double traj1_90[1];
double traj1_91[1];
double traj1_92[1];
double traj1_93[1];
double traj1_94[1];
double traj1_95[1];
double traj1_96[1];
double traj1_97[1];
double traj1_98[1];
double traj1_99[1];
double traj1_100[1];
double lambda[1];
double traj2_first[1];
double traj2_second[1];
double *traj1[101];
} Params;
typedef struct Vars_t {
double *x_1; /* 1 rows. */
double *x_2; /* 1 rows. */
double *x_3; /* 1 rows. */
double *x_4; /* 1 rows. */
double *x_5; /* 1 rows. */
double *x_6; /* 1 rows. */
double *x_7; /* 1 rows. */
double *x_8; /* 1 rows. */
double *x_9; /* 1 rows. */
double *x_10; /* 1 rows. */
double *x_11; /* 1 rows. */
double *x_12; /* 1 rows. */
double *x_13; /* 1 rows. */
double *x_14; /* 1 rows. */
double *x_15; /* 1 rows. */
double *x_16; /* 1 rows. */
double *x_17; /* 1 rows. */
double *x_18; /* 1 rows. */
double *x_19; /* 1 rows. */
double *x_20; /* 1 rows. */
double *x_21; /* 1 rows. */
double *x_22; /* 1 rows. */
double *x_23; /* 1 rows. */
double *x_24; /* 1 rows. */
double *x_25; /* 1 rows. */
double *x_26; /* 1 rows. */
double *x_27; /* 1 rows. */
double *x_28; /* 1 rows. */
double *x_29; /* 1 rows. */
double *x_30; /* 1 rows. */
double *x_31; /* 1 rows. */
double *x_32; /* 1 rows. */
double *x_33; /* 1 rows. */
double *x_34; /* 1 rows. */
double *x_35; /* 1 rows. */
double *x_36; /* 1 rows. */
double *x_37; /* 1 rows. */
double *x_38; /* 1 rows. */
double *x_39; /* 1 rows. */
double *x_40; /* 1 rows. */
double *x_41; /* 1 rows. */
double *x_42; /* 1 rows. */
double *x_43; /* 1 rows. */
double *x_44; /* 1 rows. */
double *x_45; /* 1 rows. */
double *x_46; /* 1 rows. */
double *x_47; /* 1 rows. */
double *x_48; /* 1 rows. */
double *x_49; /* 1 rows. */
double *x_50; /* 1 rows. */
double *x_51; /* 1 rows. */
double *x_52; /* 1 rows. */
double *x_53; /* 1 rows. */
double *x_54; /* 1 rows. */
double *x_55; /* 1 rows. */
double *x_56; /* 1 rows. */
double *x_57; /* 1 rows. */
double *x_58; /* 1 rows. */
double *x_59; /* 1 rows. */
double *x_60; /* 1 rows. */
double *x_61; /* 1 rows. */
double *x_62; /* 1 rows. */
double *x_63; /* 1 rows. */
double *x_64; /* 1 rows. */
double *x_65; /* 1 rows. */
double *x_66; /* 1 rows. */
double *x_67; /* 1 rows. */
double *x_68; /* 1 rows. */
double *x_69; /* 1 rows. */
double *x_70; /* 1 rows. */
double *x_71; /* 1 rows. */
double *x_72; /* 1 rows. */
double *x_73; /* 1 rows. */
double *x_74; /* 1 rows. */
double *x_75; /* 1 rows. */
double *x_76; /* 1 rows. */
double *x_77; /* 1 rows. */
double *x_78; /* 1 rows. */
double *x_79; /* 1 rows. */
double *x_80; /* 1 rows. */
double *x_81; /* 1 rows. */
double *x_82; /* 1 rows. */
double *x_83; /* 1 rows. */
double *x_84; /* 1 rows. */
double *x_85; /* 1 rows. */
double *x_86; /* 1 rows. */
double *x_87; /* 1 rows. */
double *x_88; /* 1 rows. */
double *x_89; /* 1 rows. */
double *x_90; /* 1 rows. */
double *x_91; /* 1 rows. */
double *x_92; /* 1 rows. */
double *x_93; /* 1 rows. */
double *x_94; /* 1 rows. */
double *x_95; /* 1 rows. */
double *x_96; /* 1 rows. */
double *x_97; /* 1 rows. */
double *x_98; /* 1 rows. */
double *x_99; /* 1 rows. */
double *x_100; /* 1 rows. */
double *t_01; /* 1 rows. */
double *t_02; /* 1 rows. */
double *t_03; /* 1 rows. */
double *t_04; /* 1 rows. */
double *t_05; /* 1 rows. */
double *t_06; /* 1 rows. */
double *t_07; /* 1 rows. */
double *t_08; /* 1 rows. */
double *t_09; /* 1 rows. */
double *t_10; /* 1 rows. */
double *t_11; /* 1 rows. */
double *t_12; /* 1 rows. */
double *t_13; /* 1 rows. */
double *t_14; /* 1 rows. */
double *t_15; /* 1 rows. */
double *t_16; /* 1 rows. */
double *t_17; /* 1 rows. */
double *t_18; /* 1 rows. */
double *t_19; /* 1 rows. */
double *t_20; /* 1 rows. */
double *t_21; /* 1 rows. */
double *t_22; /* 1 rows. */
double *t_23; /* 1 rows. */
double *t_24; /* 1 rows. */
double *t_25; /* 1 rows. */
double *t_26; /* 1 rows. */
double *t_27; /* 1 rows. */
double *t_28; /* 1 rows. */
double *t_29; /* 1 rows. */
double *t_30; /* 1 rows. */
double *t_31; /* 1 rows. */
double *t_32; /* 1 rows. */
double *t_33; /* 1 rows. */
double *t_34; /* 1 rows. */
double *t_35; /* 1 rows. */
double *t_36; /* 1 rows. */
double *t_37; /* 1 rows. */
double *t_38; /* 1 rows. */
double *t_39; /* 1 rows. */
double *t_40; /* 1 rows. */
double *t_41; /* 1 rows. */
double *t_42; /* 1 rows. */
double *t_43; /* 1 rows. */
double *t_44; /* 1 rows. */
double *t_45; /* 1 rows. */
double *t_46; /* 1 rows. */
double *t_47; /* 1 rows. */
double *t_48; /* 1 rows. */
double *t_49; /* 1 rows. */
double *t_50; /* 1 rows. */
double *t_51; /* 1 rows. */
double *t_52; /* 1 rows. */
double *t_53; /* 1 rows. */
double *t_54; /* 1 rows. */
double *t_55; /* 1 rows. */
double *t_56; /* 1 rows. */
double *t_57; /* 1 rows. */
double *t_58; /* 1 rows. */
double *t_59; /* 1 rows. */
double *t_60; /* 1 rows. */
double *t_61; /* 1 rows. */
double *t_62; /* 1 rows. */
double *t_63; /* 1 rows. */
double *t_64; /* 1 rows. */
double *t_65; /* 1 rows. */
double *t_66; /* 1 rows. */
double *t_67; /* 1 rows. */
double *t_68; /* 1 rows. */
double *t_69; /* 1 rows. */
double *t_70; /* 1 rows. */
double *t_71; /* 1 rows. */
double *t_72; /* 1 rows. */
double *t_73; /* 1 rows. */
double *t_74; /* 1 rows. */
double *t_75; /* 1 rows. */
double *t_76; /* 1 rows. */
double *t_77; /* 1 rows. */
double *t_78; /* 1 rows. */
double *t_79; /* 1 rows. */
double *t_80; /* 1 rows. */
double *t_81; /* 1 rows. */
double *t_82; /* 1 rows. */
double *t_83; /* 1 rows. */
double *t_84; /* 1 rows. */
double *t_85; /* 1 rows. */
double *t_86; /* 1 rows. */
double *t_87; /* 1 rows. */
double *t_88; /* 1 rows. */
double *t_89; /* 1 rows. */
double *t_90; /* 1 rows. */
double *t_91; /* 1 rows. */
double *t_92; /* 1 rows. */
double *t_93; /* 1 rows. */
double *t_94; /* 1 rows. */
double *t_95; /* 1 rows. */
double *t_96; /* 1 rows. */
double *t_97; /* 1 rows. */
double *t_98; /* 1 rows. */
double *x[101];
} Vars;
typedef struct Workspace_t {
double *h;
double *s_inv;
double *s_inv_z;
double b[100];
double q[198];
double rhs[298];
double x[298];
double *s;
double *z;
double *y;
double lhs_aff[298];
double lhs_cc[298];
double buffer[298];
double buffer2[298];
double KKT[593];
double L[493];
double d[298];
double v[298];
double d_inv[298];
double gap;
double optval;
double ineq_resid_squared;
double eq_resid_squared;
double block_33[1];
/* Pre-op symbols. */
double quad_309377593344[1];
double quad_170383695872[1];
double quad_112192413696[1];
double quad_271369404416[1];
double quad_974379421696[1];
double quad_880958541824[1];
double quad_572094451712[1];
double quad_789148684288[1];
double quad_448304680960[1];
double quad_196635672576[1];
double quad_489733091328[1];
double quad_802233995264[1];
double quad_865562517504[1];
double quad_910621253632[1];
double quad_321513025536[1];
double quad_997344780288[1];
double quad_448780910592[1];
double quad_115901485056[1];
double quad_782888361984[1];
double quad_609463140352[1];
double quad_88437858304[1];
double quad_984663347200[1];
double quad_230162866176[1];
double quad_416382242816[1];
double quad_380873158656[1];
double quad_556464291840[1];
double quad_266292043776[1];
double quad_970572640256[1];
double quad_39497891840[1];
double quad_701607514112[1];
double quad_181586403328[1];
double quad_260463075328[1];
double quad_382856859648[1];
double quad_199224414208[1];
double quad_511656841216[1];
double quad_171214155776[1];
double quad_70639910912[1];
double quad_463249276928[1];
double quad_244412502016[1];
double quad_258282409984[1];
double quad_321028120576[1];
double quad_30674518016[1];
double quad_824505257984[1];
double quad_484111179776[1];
double quad_675570683904[1];
double quad_386911121408[1];
double quad_932702867456[1];
double quad_274526810112[1];
double quad_96616189952[1];
double quad_711864590336[1];
double quad_200392192000[1];
double quad_150270558208[1];
double quad_598460686336[1];
double quad_831592636416[1];
double quad_874189471744[1];
double quad_632352092160[1];
double quad_969116119040[1];
double quad_610911072256[1];
double quad_606707699712[1];
double quad_449159319552[1];
double quad_700922720256[1];
double quad_911067136000[1];
double quad_304706789376[1];
double quad_530900680704[1];
double quad_307691851776[1];
double quad_875119529984[1];
double quad_330167877632[1];
double quad_106008100864[1];
double quad_586821791744[1];
double quad_62270459904[1];
double quad_705160380416[1];
double quad_566627430400[1];
double quad_833211822080[1];
double quad_28799266816[1];
double quad_442252132352[1];
double quad_713742774272[1];
double quad_447903891456[1];
double quad_655034785792[1];
double quad_576686788608[1];
double quad_288749699072[1];
double quad_866096066560[1];
double quad_345799389184[1];
double quad_335292588032[1];
double quad_292534816768[1];
double quad_832380674048[1];
double quad_934938374144[1];
double quad_265476059136[1];
double quad_478224822272[1];
double quad_901249572864[1];
double quad_216942473216[1];
double quad_227493912576[1];
double quad_458072092672[1];
double quad_912331198464[1];
double quad_307004768256[1];
double quad_284125421568[1];
double quad_704038281216[1];
double quad_401987686400[1];
double quad_592084643840[1];
double quad_8875266048[1];
double quad_270270570496[1];
int converged;
} Workspace;
typedef struct Settings_t {
double resid_tol;
double eps;
int max_iters;
int refine_steps;
int better_start;
/* Better start obviates the need for s_init and z_init. */
double s_init;
double z_init;
int verbose;
/* Show extra details of the iterative refinement steps. */
int verbose_refinement;
int debug;
/* For regularization. Minimum value of abs(D_ii) in the kkt D factor. */
double kkt_reg;
} Settings;
extern Vars vars;
extern Params params;
extern Workspace work;
extern Settings settings;
/* Function definitions in ldl.c: */
void ldl_solve(double *target, double *var);
void ldl_factor(void);
double check_factorization(void);
void matrix_multiply(double *result, double *source);
double check_residual(double *target, double *multiplicand);
void fill_KKT(void);
/* Function definitions in matrix_support.c: */
void multbymA(double *lhs, double *rhs);
void multbymAT(double *lhs, double *rhs);
void multbymG(double *lhs, double *rhs);
void multbymGT(double *lhs, double *rhs);
void multbyP(double *lhs, double *rhs);
void fillq(void);
void fillh(void);
void fillb(void);
void pre_ops(void);
/* Function definitions in solver.c: */
double eval_gap(void);
void set_defaults(void);
void setup_pointers(void);
void setup_indexed_params(void);
void setup_indexed_optvars(void);
void setup_indexing(void);
void set_start(void);
double eval_objv(void);
void fillrhs_aff(void);
void fillrhs_cc(void);
void refine(double *target, double *var);
double calc_ineq_resid_squared(void);
double calc_eq_resid_squared(void);
void better_start(void);
void fillrhs_start(void);
long solve(void);
/* Function definitions in testsolver.c: */
int main(int argc, char **argv);
void load_default_data(const mat& traj1, const mat& traj2);
/* Function definitions in util.c: */
void tic(void);
float toc(void);
float tocq(void);
void printmatrix(char *name, double *A, int m, int n, int sparse);
double unif(double lower, double upper);
float ran1(long*idum, int reset);
float randn_internal(long *idum, int reset);
double randn(void);
void reset_rand(void);
#endif
#include "plotMat3.h"
#include "plotgnu3.h"
#include <string>
using namespace std;
using namespace arma;
void plotMat3(const arma::mat& traj, const string& labelname) {
vector<double> x;
for (int i = 0; i < traj.n_rows; ++i) {
x.push_back(traj(i,0));
}
vector<double> y;
for (int i = 0; i < traj.n_rows; ++i) {
y.push_back(traj(i,1));
}
vector<double> z;
for (int i = 0; i < traj.n_rows; ++i) {
z.push_back(traj(i,2));
}
plotgnu3(x,y,z,labelname);
}
#include <armadillo>
#include <vector>
#include <string>
using namespace std;
using namespace arma;
#ifndef plotMat3_H
#define plotMat3_H
void plotMat3(const arma::mat& traj, const string& labelname);
#endif
#include "plotgnu3.h"
#include "gnuplot-cpp/gnuplot_i.hpp" //Gnuplot class handles POSIX-Pipe-communikation with Gnuplot
using namespace std;
void wait_for_key ()
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__) // every keypress registered, also arrow keys
cout << endl << "Press any key to continue..." << endl;
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE));
_getch();
#elif defined(unix) || defined(__unix) || defined(__unix__) || defined(__APPLE__)
cout << endl << "Press ENTER to continue..." << endl;
std::cin.clear();
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cin.get();
#endif
return;
}
void plotgnu3(const vector<double>& x, const vector<double>& y, const vector<double>& z, const string& labelname) {
static Gnuplot g1("lines");