Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ set(hipo_sources
ipm/hipo/ipm/FactorHiGHSSolver.cpp
ipm/hipo/ipm/Control.cpp
ipm/hipo/ipm/Iterate.cpp
ipm/hipo/ipm/LogHighs.cpp
ipm/hipo/ipm/KktMatrix.cpp
ipm/hipo/ipm/Model.cpp
ipm/hipo/ipm/PreProcess.cpp
ipm/hipo/ipm/Refine.cpp
Expand All @@ -195,8 +195,8 @@ set(hipo_headers
ipm/hipo/ipm/Control.h
ipm/hipo/ipm/Info.h
ipm/hipo/ipm/Iterate.h
ipm/hipo/ipm/KktMatrix.h
ipm/hipo/ipm/LinearSolver.h
ipm/hipo/ipm/LogHighs.h
ipm/hipo/ipm/Model.h
ipm/hipo/ipm/Options.h
ipm/hipo/ipm/PreProcess.h
Expand Down Expand Up @@ -246,14 +246,14 @@ set(factor_highs_headers
set(hipo_util_sources
ipm/hipo/auxiliary/Auxiliary.cpp
ipm/hipo/auxiliary/KrylovMethods.cpp
ipm/hipo/auxiliary/Log.cpp
ipm/hipo/auxiliary/Logger.cpp
ipm/hipo/auxiliary/VectorOperations.cpp)

set(hipo_util_headers
ipm/hipo/auxiliary/Auxiliary.h
ipm/hipo/auxiliary/IntConfig.h
ipm/hipo/auxiliary/KrylovMethods.h
ipm/hipo/auxiliary/Log.h
ipm/hipo/auxiliary/Logger.h
ipm/hipo/auxiliary/mycblas.h
ipm/hipo/auxiliary/OrderingPrint.h
ipm/hipo/auxiliary/VectorOperations.h)
Expand Down
71 changes: 71 additions & 0 deletions highs/ipm/hipo/auxiliary/Auxiliary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,77 @@ void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
}
}

void permuteSym(const std::vector<Int>& iperm, std::vector<Int>& ptr,
std::vector<Int>& rows, std::vector<double>& val, bool lower) {
// Symmetric permutation of the lower (upper) triangular matrix M based on
// inverse permutation iperm. The resulting matrix is lower (upper) triangular,
// regardless of the input matrix.

const Int n = ptr.size() - 1;
std::vector<Int> work(n, 0);
const bool use_val = !val.empty();

// go through the columns to count the nonzeros
for (Int j = 0; j < n; ++j) {
// get new index of column
const Int col = iperm[j];

// go through elements of column
for (Int el = ptr[j]; el < ptr[j + 1]; ++el) {
const Int i = rows[el];

// ignore potential entries in upper(lower) triangular part
if ((lower && i < j) || (!lower && i > j)) continue;

// get new index of row
const Int row = iperm[i];

// if only lower triangular part is used, col is smaller than row
Int actual_col = lower ? std::min(row, col) : std::max(row, col);
++work[actual_col];
}
}

std::vector<Int> new_ptr(n + 1);

// get column pointers by summing the count of nonzeros in each column.
// copy column pointers into work
counts2Ptr(new_ptr, work);

std::vector<Int> new_rows(new_ptr.back());
std::vector<double> new_val;
if (use_val) new_val.resize(new_ptr.back());

// go through the columns to assign row indices
for (Int j = 0; j < n; ++j) {
// get new index of column
const Int col = iperm[j];

// go through elements of column
for (Int el = ptr[j]; el < ptr[j + 1]; ++el) {
const Int i = rows[el];

// ignore potential entries in upper triangular part
if ((lower && i < j) || (!lower && i > j)) continue;

// get new index of row
const Int row = iperm[i];

// if only lower triangular part is used, col is smaller than row
const Int actual_col = lower ? std::min(row, col) : std::max(row, col);
const Int actual_row = lower ? std::max(row, col) : std::min(row, col);

Int pos = work[actual_col]++;
new_rows[pos] = actual_row;
if (use_val) new_val[pos] = val[el];
}
}

ptr = std::move(new_ptr);
rows = std::move(new_rows);
if (use_val) val = std::move(new_val);
}

void childrenLinkedList(const std::vector<Int>& parent, std::vector<Int>& head,
std::vector<Int>& next) {
// Create linked lists of children in elimination tree.
Expand Down
2 changes: 2 additions & 0 deletions highs/ipm/hipo/auxiliary/Auxiliary.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
void transpose(const std::vector<Int>& ptr, const std::vector<Int>& rows,
const std::vector<double>& val, std::vector<Int>& ptrT,
std::vector<Int>& rowsT, std::vector<double>& valT);
void permuteSym(const std::vector<Int>& iperm, std::vector<Int>& ptr,
std::vector<Int>& rows, std::vector<double>& val, bool lower);
void childrenLinkedList(const std::vector<Int>& parent, std::vector<Int>& head,
std::vector<Int>& next);
void reverseLinkedList(std::vector<Int>& head, std::vector<Int>& next);
Expand Down
2 changes: 0 additions & 2 deletions highs/ipm/hipo/auxiliary/KrylovMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <iostream>

#include "VectorOperations.h"
#include "ipm/hipo/auxiliary/Log.h"

namespace hipo {

Expand Down Expand Up @@ -182,7 +181,6 @@ Int Cg(const AbstractMatrix* M, const AbstractMatrix* P,
++iter;

if (isNanVector(x)) {
// log->printDevInfo("CG: x is nan at iter %d\n", (int)iter);
break;
}
}
Expand Down
60 changes: 0 additions & 60 deletions highs/ipm/hipo/auxiliary/Log.cpp

This file was deleted.

62 changes: 0 additions & 62 deletions highs/ipm/hipo/auxiliary/Log.h

This file was deleted.

42 changes: 42 additions & 0 deletions highs/ipm/hipo/auxiliary/Logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "Logger.h"

namespace hipo {

void Logger::setOptions(const HighsLogOptions* log_options) {
log_options_ = log_options;
}

bool Logger::debug(Int level) const {
// Return true if level agrees with log_dev_level

if (log_options_ && log_options_->log_dev_level) {
if (*log_options_->log_dev_level == kHighsLogDevLevelInfo)
return level == 1;

if (*log_options_->log_dev_level == kHighsLogDevLevelDetailed)
return level == 1 || level == 2;

if (*log_options_->log_dev_level == kHighsLogDevLevelVerbose)
return level == 1 || level == 2 || level == 3;
}
return false;
}

std::string format(double d, Int width, Int prec,
std::ios_base::fmtflags floatfield) {
std::ostringstream s;
s.precision(prec);
s.width(width);
s.setf(floatfield, std::ios_base::floatfield);
s << d;
return s.str();
}

std::string integer(Int i, Int width) {
std::ostringstream s;
s.width(width);
s << i;
return s.str();
}

} // namespace hipo
79 changes: 79 additions & 0 deletions highs/ipm/hipo/auxiliary/Logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef HIPO_LOGGER_H
#define HIPO_LOGGER_H

#include <sstream>

#include "io/HighsIO.h"
#include "ipm/hipo/auxiliary/IntConfig.h"

// Class for Highs logging
// Use setOptions to pass the log_options.

namespace hipo {

class Logger {
const HighsLogOptions* log_options_;

public:
Logger() = default;
void setOptions(const HighsLogOptions* log_options);
bool debug(Int level) const;

template <typename... Args>
void print(const char* format, Args... args) const {
if (log_options_)
highsLogUser(*log_options_, HighsLogType::kInfo, format, args...);
}

template <typename... Args>
void printw(const char* format, Args... args) const {
if (log_options_)
highsLogUser(*log_options_, HighsLogType::kWarning, format, args...);
}

template <typename... Args>
void printe(const char* format, Args... args) const {
if (log_options_)
highsLogUser(*log_options_, HighsLogType::kError, format, args...);
}

template <typename... Args>
void printInfo(const char* format, Args... args) const {
if (log_options_)
highsLogDev(*log_options_, HighsLogType::kInfo, format, args...);
}

template <typename... Args>
void printDetailed(const char* format, Args... args) const {
if (log_options_)
highsLogDev(*log_options_, HighsLogType::kDetailed, format, args...);
}

template <typename... Args>
void printVerbose(const char* format, Args... args) const {
if (log_options_)
highsLogDev(*log_options_, HighsLogType::kVerbose, format, args...);
}
};

// Functions to print using streams, taken from IPX.
std::string format(double d, Int width, Int prec,
std::ios_base::fmtflags floatfield);
std::string integer(Int i, Int width = 0);
inline std::string sci(double d, Int width, Int prec) {
return format(d, width, prec, std::ios_base::scientific);
}
inline std::string fix(double d, Int width, Int prec) {
return format(d, width, prec, std::ios_base::fixed);
}
template <typename T>
std::string textline(const T& text) {
std::ostringstream s;
s.setf(std::ios_base::left);
s.width(32);
s << text;
return s.str();
}

} // namespace hipo
#endif
Loading
Loading