Program Listing for File mp_param.h
↰ Return to documentation for file (include/mathopt/mp_param/mp_param.h
)
/* #############################################
* This file is part of
* ZERO
*
* Copyright (c) 2020
* Released under the Creative Commons
* CC BY-NC-SA 4.0 License
*
* Find out more at
* https://github.com/ds4dm/ZERO
* #############################################*/
#pragma once
#include "zero.h"
#include <armadillo>
#include <gurobi_c++.h>
#include <iostream>
#include <memory>
#include <set>
#include <string>
namespace MathOpt {
class MP_Param {
private:
double Eps{1e-6};
protected:
arma::sp_mat Q;
arma::sp_mat A;
arma::sp_mat B;
arma::sp_mat C;
arma::sp_mat B_bounds;
arma::vec b_bounds;
arma::vec c;
arma::vec d;
arma::vec b;
GRBEnv *Env;
VariableBounds Bounds;
// Object for sizes and integrity check
unsigned int numParams;
unsigned int numVars;
unsigned int numConstr;
unsigned int size();
bool dataCheck(bool forceSymmetry = true) const;
void detectBounds();
void rewriteBounds();
virtual bool finalize();
public:
// Default constructors
MP_Param(GRBEnv *env = nullptr) : Env{env} {};
MP_Param(const MP_Param &M) = default;
// Getters and setters
arma::sp_mat getQ() const { return this->Q; }
arma::sp_mat getC() const { return this->C; }
arma::sp_mat getA(bool bounds = true) const;
arma::sp_mat getB(bool bounds = true) const;
arma::vec getc() const { return this->c; }
arma::vec getd() const { return this->d; }
arma::vec getb(bool bounds = true) const;
unsigned int getNumParams() const {
return this->numParams;
}
unsigned int getNumVars() const {
return this->numVars;
}
VariableBounds getBounds() const { return this->Bounds; }
MP_Param &setQ(const arma::sp_mat &Q_in) {
this->Q = Q_in;
return *this;
}
MP_Param &setC(const arma::sp_mat &C_in) {
this->C = C_in;
return *this;
}
MP_Param &setA(const arma::sp_mat &A_in) {
this->A = A_in;
return *this;
}
MP_Param &setB(const arma::sp_mat &B_in) {
this->B = B_in;
return *this;
}
MP_Param &setc(const arma::vec &c_in) {
this->c = c_in;
return *this;
}
MP_Param &setd(const arma::vec &d_in) {
this->d = d_in;
return *this;
}
MP_Param &setb(const arma::vec &b_in) {
this->b = b_in;
return *this;
}
MP_Param &setBounds(const VariableBounds &bounds_in) {
this->Bounds = bounds_in;
// Update the bound processing and update sizes.
this->rewriteBounds();
return *this;
}
// Setters and advanced constructors
virtual MP_Param &set(const arma::sp_mat &Q_in,
const arma::sp_mat &C_in,
const arma::sp_mat &A_in,
const arma::sp_mat &B_in,
const arma::vec &c_in,
const arma::vec &b_in,
const arma::vec &d_in); // Copy data into this
virtual MP_Param &set(arma::sp_mat &&Q_in,
arma::sp_mat &&C_in,
arma::sp_mat &&A_in,
arma::sp_mat &&B_in,
arma::vec &&c_in,
arma::vec &&b_in,
arma::vec &&d_in); // Move data into this
virtual MP_Param &set(const QP_Objective &obj, const QP_Constraints &cons);
virtual MP_Param &set(QP_Objective &&obj, QP_Constraints &&cons);
virtual MP_Param &addDummy(unsigned int pars, unsigned int vars = 0, int position = -1);
virtual void save(const std::string &filename, bool append) const;
virtual long int load(const std::string &filename, long int pos = 0);
virtual unsigned int KKT(arma::sp_mat &M, arma::sp_mat &N, arma::vec &q) const = 0;
virtual std::unique_ptr<GRBModel> solveFixed(const arma::vec x, bool solve = false) = 0;
virtual double computeObjective(const arma::vec &y,
const arma::vec &x,
bool checkFeas = true,
double tol = 1e-6) const;
void forceDataCheck() const;
virtual bool isFeasible(const arma::vec &y, const arma::vec &x, double tol) const;
};
} // namespace MathOpt
#include "ip_param.h"
#include "qp_param.h"