Program Listing for File ip_param.h
↰ Return to documentation for file (include/mathopt/mp_param/ip_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 "support/codes.h"
#include "zero.h"
#include <armadillo>
#include <gurobi_c++.h>
#include <iostream>
#include <memory>
#include <set>
#include <string>
namespace MathOpt {
std::ostream &operator<<(std::ostream &os, const IP_Param &I);
class IP_Param : public MP_Param {
private:
GRBModel IPModel;
arma::vec Integers;
bool Finalized{false};
// These methods should be inaccessible to the inheritor, since we have a
// different structure.
using MP_Param::set;
public: // Constructors
explicit IP_Param(GRBEnv *env = nullptr) : MP_Param(env), IPModel{GRBModel(*env)} {
this->size();
}
IP_Param(const arma::sp_mat &C_in,
const arma::sp_mat &B_in,
const arma::vec &b_in,
const arma::vec &c_in,
const arma::vec &d_in,
const arma::vec &integers_in,
const VariableBounds &Bounds_in,
GRBEnv *env_in);
arma::vec getIntegers() const {
return this->Integers;
}
bool finalize() override;
IP_Param &setBounds(const VariableBounds &boundIn);
bool addConstraints(const arma::sp_mat &A_in, const arma::vec &b_in);
IP_Param(const IP_Param &ipg) = default;
// Override setters
MathOpt::IP_Param &set(const arma::sp_mat &C_in,
const arma::sp_mat &B_in,
const arma::vec &b_in,
const arma::vec &c_in,
const arma::vec &d_in,
const arma::vec &integers_in,
const VariableBounds &Bounds_in); // Copy data into this
IP_Param &set(arma::sp_mat &&C_in,
arma::sp_mat &&B_in,
arma::vec &&b_in,
arma::vec &&c_in,
arma::vec &&d_in,
arma::vec &&integers_in,
VariableBounds &&Bounds_in); // Copy data into this
bool operator==(const IP_Param &IPG2) const;
double computeObjective(const arma::vec &y,
const arma::vec &x,
bool checkFeas = true,
double tol = 1e-6) const override;
void save(const std::string &filename, bool append) const override;
long load(const std::string &filename, long pos = 0) override;
void updateModelObjective(const arma::vec &x);
std::unique_ptr<GRBModel> solveFixed(arma::vec x, bool solve = false) override;
std::unique_ptr<GRBModel> getIPModel(const arma::vec &x, bool relax = false);
unsigned int KKT(arma::sp_mat &M, arma::sp_mat &N, arma::vec &q) const override;
bool isFeasible(const arma::vec &y, const arma::vec &x, double tol) const override;
void presolve();
};
} // namespace MathOpt