Linux平台下编译及冗余文件删除

This commit is contained in:
2025-08-25 13:33:35 +08:00
parent a78045b4d3
commit 9f029ef7e4
4 changed files with 25 additions and 104 deletions

4
.gitignore vendored
View File

@@ -1 +1,5 @@
build
.vscode
CMakeFiles
CMakeCache.*
Makefile

View File

@@ -1,73 +0,0 @@
# ------------------------------------------------------------------------------
# This file sets up Gurobi for CMake. Once done this will define
#
# GUROBI_FOUND - system has GUROBI
# GUROBI_INCLUDE_DIRS - the GUROBI include directories
# GUROBI_LIBRARIES - Link these to use GUROBI
#
# In your CMakeLists file, you need to add, e.g. (modify it if necessary):
# if (GUROBI_FOUND)
# message(STATUS "Gurobi include dir: " ${GUROBI_INCLUDE_DIRS})
# message(STATUS "Gurobi libraries: " ${GUROBI_LIBRARIES})
# target_compile_definitions(${PROJECT_NAME} PUBLIC HAS_GUROBI)
# target_include_directories(${PROJECT_NAME} PRIVATE ${GUROBI_INCLUDE_DIRS})
# target_link_libraries(${PROJECT_NAME} PRIVATE ${GUROBI_LIBRARIES})
# endif()
# ------------------------------------------------------------------------------
# Is it already configured?
if (NOT GUROBI_FOUND)
# Hardcoded search paths
set(SEARCH_PATHS_FOR_HEADERS
"$ENV{GUROBI_HOME}/include"
"/Library/gurobi1001/mac64/include"
"C:\\gurobi1001\\win64\\include"
)
set(SEARCH_PATHS_FOR_LIBRARIES
"$ENV{GUROBI_HOME}/lib"
"/Library/gurobi1001/mac64/lib"
"C:\\gurobi1001\\win64\\lib"
)
find_path(GUROBI_INCLUDE_DIR gurobi_c++.h
PATHS ${SEARCH_PATHS_FOR_HEADERS}
)
find_library( GUROBI_C_LIBRARY
NAMES gurobi100 gurobi105 libgurobi
PATHS ${SEARCH_PATHS_FOR_LIBRARIES}
)
find_library( GUROBI_CXX_LIBRARY_DEBUG
NAMES gurobi_c++ gurobi_c++mdd2017
PATHS ${SEARCH_PATHS_FOR_LIBRARIES}
)
find_library( GUROBI_CXX_LIBRARY_RELEASE
NAMES gurobi_c++ gurobi_c++md2017
PATHS ${SEARCH_PATHS_FOR_LIBRARIES}
)
# setup header file directories
set(GUROBI_INCLUDE_DIRS ${GUROBI_INCLUDE_DIR})
# setup libraries files
set(GUROBI_LIBRARIES
debug ${GUROBI_CXX_LIBRARY_DEBUG}
optimized ${GUROBI_CXX_LIBRARY_RELEASE}
${GUROBI_C_LIBRARY}
)
endif()
# Check that Gurobi was successfully found
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_INCLUDE_DIRS)
find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_LIBRARIES)
# Hide variables from CMake-Gui options
mark_as_advanced(GUROBI_LIBRARIES GUROBI_INCLUDE_DIRS GUROBI_INCLUDE_DIR)

View File

@@ -1,17 +0,0 @@
#pragma once
#include <vector>
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;
};
}

View File

@@ -6,6 +6,9 @@
#include <algorithm>
#include <stack>
#include <cassert>
#include <cstring>
#include <cfloat>
#include <math.h>
using namespace sv;
using std::make_pair;
@@ -64,14 +67,14 @@ LinSolver& sv::LinSolver::operator=(const LinSolver& solver)
if (this == &solver) {
return *this;
}
delete[] vars; // <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD>ڴ<EFBFBD>
delete[] vars; // <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD>ڴ<EFBFBD>
vars = nullptr;
cn = solver.cn;
if (cn > 0) {
vars = new Var[cn];
for (int i = 0; i < cn; i++) {
vars[i] = solver.vars[i]; // <20><EFBFBD><EEBFBD>
vars[i] = solver.vars[i]; // <20><EFBFBD><EEBFBD>
}
}
table = solver.table;
@@ -101,7 +104,7 @@ Var* LinSolver::addVars(int num, VarType type)
const Var& sv::LinSolver::getVar(int idx)
{
assert(idx >= 0 && idx < cn); // <20><><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
assert(idx >= 0 && idx < cn); // <20><><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD>
return vars[idx];
}
@@ -203,7 +206,11 @@ rtn Model::optimize()
std::stack<Node> list_;
Node root_node(solver, 0, solver.obj_);
Node root_node;
root_node.solver = solver;
root_node.lower_bound = 0;
root_node.upper_bound = solver.obj_;
Node incumbent_node = root_node;
list_.push(root_node);
@@ -325,7 +332,7 @@ rtn LinSolver::feasible_solution()
basic.push_back(cn - bn + i);
}
// === <20>жϳ<D0B6>ʼ<EFBFBD><CABC><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>н<EFBFBD> ===
// === <20>жϳ<D0B6>ʼ<EFBFBD><CABC><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>н<EFBFBD> ===
bool initial_feasible = true;
for (int row = 1; row < bn; row++) {
if (ope_table.at(row).front() < 0) {
@@ -334,7 +341,7 @@ rtn LinSolver::feasible_solution()
}
}
// === <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>н<EFBFBD> ===
// === <20><><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>н<EFBFBD> ===
if (!initial_feasible) {
vector<double> coeff = ope_table.front();
ope_table.front() = vector<double>(cn, .0);
@@ -386,10 +393,10 @@ rtn LinSolver::feasible_solution()
rtn LinSolver::_pivot(pair<size_t, size_t>& p)
{
p = make_pair(0, 0);
double cmin = INT_MAX;
double cmin = DBL_MAX;
vector<double> coef = ope_table.front();
// === <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ ===
// === <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԫ<EFBFBD><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сֵ ===
for (size_t col = 1; col < coef.size(); col++) {
if (cmin > coef.at(col) && find(basic.begin(), basic.end(), col) == basic.end()) {
cmin = coef.at(col);
@@ -399,7 +406,7 @@ rtn LinSolver::_pivot(pair<size_t, size_t>& p)
if (cmin >= 0) {
return OPTIMAL;
}
double bmin = INT_MAX;
double bmin = DBL_MAX;
for (size_t row = 1; row < bn; row++) {
double tmp = ope_table.at(row).front() / ope_table.at(row).at(p.second);
if (ope_table.at(row).at(p.second) > 0 && bmin > tmp) {
@@ -408,7 +415,7 @@ rtn LinSolver::_pivot(pair<size_t, size_t>& p)
}
}
if (abs(bmin - INT_MAX) < 1e-10) {
if (abs(bmin - DBL_MAX) < 1e-10) {
return UNBOUNDED;
}
@@ -426,13 +433,13 @@ void LinSolver::_gaussian(pair<size_t, size_t> p)
{
size_t x = p.first, y = p.second;
// === <20><><EFBFBD>й<EFBFBD>һ<EFBFBD><D2BB> ===
// === <20><><EFBFBD>й<EFBFBD>һ<EFBFBD><D2BB> ===
double norm = ope_table.at(x).at(y);
for (size_t col = 0; col < ope_table.at(x).size(); col++) {
ope_table.at(x).at(col) /= norm;
}
// === <20><><EFBFBD><EFBFBD><EFBFBD>б任 ===
// === <20><><EFBFBD><EFBFBD><EFBFBD>б任 ===
for (size_t row = 0; row < bn; row++) {
if (row == x) {
continue;
@@ -444,6 +451,6 @@ void LinSolver::_gaussian(pair<size_t, size_t> p)
}
}
}
basic.at(x - 1) = y; // <20><>Ԫ
basic.at(x - 1) = y; // <20><>Ԫ
}