分支定界法基本框架
This commit is contained in:
@ -87,17 +87,28 @@ namespace sv {
|
||||
EQUAL
|
||||
};
|
||||
|
||||
|
||||
enum class VarType {
|
||||
CONTINUOUS,
|
||||
BINARY,
|
||||
INTEGER,
|
||||
};
|
||||
|
||||
class Var {
|
||||
public:
|
||||
Var(double coef = 1) :col(0), val(0), coeffs(coef) {};
|
||||
friend class Model;
|
||||
friend class LinSolver;
|
||||
friend class Expr;
|
||||
|
||||
Var(double coef = 1, VarType type_ = VarType::CONTINUOUS);
|
||||
double get(DoubleAttr attr);
|
||||
int get(IntAttr attr);
|
||||
friend class Model;
|
||||
friend class Expr;
|
||||
|
||||
private:
|
||||
double coeffs;
|
||||
double val;
|
||||
int col;
|
||||
VarType type;
|
||||
};
|
||||
|
||||
Expr operator+(const Expr& x, const Expr& y);
|
||||
@ -131,7 +142,7 @@ namespace sv {
|
||||
Expr(double constant = 0.0);
|
||||
Expr(Var var, double coeff = 1.0);
|
||||
|
||||
friend class Model;
|
||||
friend class LinSolver;
|
||||
|
||||
friend Expr operator+(const Expr& x, const Expr& y);
|
||||
friend Expr operator+(const Expr& x);
|
||||
|
16
inc/node.hpp
16
inc/node.hpp
@ -1,5 +1,17 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
class Node {
|
||||
namespace sv {
|
||||
class Var;
|
||||
class Model;
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Model* mdl;
|
||||
double lower_bound;
|
||||
double upper_bound;
|
||||
|
||||
};
|
||||
bool is_integer;
|
||||
std::vector<Var> branch_list;
|
||||
};
|
||||
}
|
||||
|
@ -3,31 +3,59 @@
|
||||
|
||||
namespace sv {
|
||||
|
||||
class Model
|
||||
{
|
||||
class LinSolver {
|
||||
public:
|
||||
Model();
|
||||
Var* addVars(int col);
|
||||
friend class Model;
|
||||
LinSolver();
|
||||
~LinSolver();
|
||||
|
||||
LinSolver(const LinSolver& solver);
|
||||
LinSolver& operator=(const LinSolver& solver);
|
||||
|
||||
Var* addVars(int col, VarType type);
|
||||
const Var& getVar(int idx);
|
||||
void addConstr(const Expr& expr, ConstrOper sense, double rhs);
|
||||
void setObjective(Expr obje, int sense = MDL_MAXIMIZE);
|
||||
void print();
|
||||
rtn optimize();
|
||||
|
||||
double get(DoubleAttr attr);
|
||||
int get(IntAttr attr);
|
||||
private:
|
||||
|
||||
rtn optimize();
|
||||
protected:
|
||||
|
||||
double _simplex();
|
||||
rtn _pivot(std::pair<size_t, size_t>& p);
|
||||
rtn feasible_solution();
|
||||
void _gaussian(std::pair<size_t, size_t> p);
|
||||
|
||||
Var* vars;
|
||||
|
||||
matrix mt;
|
||||
matrix mt_cvt;
|
||||
size_t cn, bn;
|
||||
std::vector<int> basic;
|
||||
rtn rtn_;
|
||||
double res_;
|
||||
double obj_;
|
||||
int sense;
|
||||
};
|
||||
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
Model();
|
||||
rtn optimize();
|
||||
|
||||
Var* addVars(int col, VarType type);
|
||||
void addConstr(const Expr& expr, ConstrOper sense, double rhs);
|
||||
void setObjective(Expr obje, int sense = MDL_MAXIMIZE);
|
||||
|
||||
double get(DoubleAttr attr);
|
||||
int get(IntAttr attr);
|
||||
|
||||
private:
|
||||
LinSolver solver;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user