Skip to content

Commit d763c57

Browse files
authored
Merge pull request #93 from sandialabs/dev-weh
Misc coek updates
2 parents cc44423 + 65fe25e commit d763c57

File tree

12 files changed

+187
-53
lines changed

12 files changed

+187
-53
lines changed

Diff for: build.sh

+18-6
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,31 @@
66
# This uses Spack to install third-party dependencies in the `_spack` directory.
77
#
88
clang=0
9+
compact="OFF"
910
debug="OFF"
1011
python_exe=""
1112
spack_dev=0
1213
spack_env="coekenv"
1314
spack_home=`pwd`/_spack
1415
spack_reinstall=0
1516
with_python="OFF"
17+
with_scip=""
18+
scip_config="OFF"
1619
with_valgrind=""
1720
while [[ $# -gt 0 ]]; do
1821
case $1 in
1922
--help)
20-
echo "build.sh [--help] [--clang] [--debug] [--python] [--python-exe <file>] [--spack-dev] [--spack-env <env>] [--spack-home <dir>] [--spack-reinstall] [--valgrind]"
23+
echo "build.sh [--help] [--clang] [--compact] [--debug] [--python] [--python-exe <file>] [--scip] [--spack-dev] [--spack-env <env>] [--spack-home <dir>] [--spack-reinstall] [--valgrind]"
2124
exit
2225
;;
2326
--clang)
2427
clang=1
2528
shift
2629
;;
30+
--compact)
31+
compact="ON"
32+
shift
33+
;;
2734
--debug)
2835
debug="ON"
2936
shift
@@ -41,6 +48,11 @@ while [[ $# -gt 0 ]]; do
4148
python_exe="-DPython_EXECUTABLE=$2"
4249
shift
4350
;;
51+
--scip)
52+
with_scip="scip"
53+
scip_config="ON"
54+
shift
55+
;;
4456
--spack-dev)
4557
spack_dev=1
4658
shift
@@ -119,16 +131,16 @@ else
119131
git clone https://github.com/spack/spack.git ${SPACK_HOME}
120132
. ${SPACK_HOME}/share/spack/setup-env.sh
121133
echo "Adding _spack_tpls"
122-
spack repo remove _spack_tpls/repo | true
123-
spack repo add _spack_tpls/repo
134+
spack repo remove `pwd`/_spack_tpls/repo | true
135+
spack repo add `pwd`/_spack_tpls/repo
124136
spack repo list
125137
spack env create $spack_env
126138
spack env activate $spack_env
127139
spack compiler find
128-
spack add asl fmt rapidjson catch2 highs $with_valgrind
140+
spack add asl fmt@8.0.1 rapidjson catch2 highs $with_valgrind $with_scip
129141
spack install
130142
spack env deactivate
131-
spack repo remove _spack_tpls/repo
143+
spack repo remove `pwd`/_spack_tpls/repo
132144
fi
133145
if test -d ${SPACK_HOME}; then
134146
export SPACK_HOME=$(cd ${SPACK_HOME}; pwd)
@@ -141,7 +153,7 @@ echo "Building Coek"
141153
echo ""
142154
mkdir _build
143155
cd _build
144-
cmake -DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/${spack_env}/.spack-env/view -Dwith_debug=${debug} -Dwith_python=${with_python} $python_exe -Dwith_gurobi=$with_gurobi -Dwith_highs=ON -Dwith_cppad=OFF -Dwith_fmtlib=ON -Dwith_rapidjson=ON -Dwith_catch2=ON -Dwith_tests=ON -Dwith_asl=ON -Dwith_openmp=OFF ..
156+
cmake -DCMAKE_PREFIX_PATH=${SPACK_HOME}/var/spack/environments/${spack_env}/.spack-env/view -Dwith_debug=${debug} -Dwith_python=${with_python} -Dwith_pybind11=${with_python} $python_exe -Dwith_gurobi=$with_gurobi -Dwith_highs=ON -Dwith_cppad=OFF -Dwith_fmtlib=ON -Dwith_rapidjson=ON -Dwith_catch2=ON -Dwith_tests=ON -Dwith_asl=ON -Dwith_openmp=OFF -Dwith_compact=${compact} ..
145157
make -j20
146158
make install
147159

Diff for: lib/coek/coek/api/indexed_container.defs.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <type_traits>
4+
35
namespace coek {
46

57
template <class TYPE>
@@ -37,7 +39,7 @@ class IndexedComponentRepn_multiarray : public IndexedComponentRepn<TYPE> {
3739
{
3840
for (size_t i = 0; i < this->_dim; ++i) {
3941
size_t tmp = static_cast<size_t>(args[i]);
40-
if ((tmp < 0) or (tmp >= shape[i]))
42+
if (tmp >= shape[i])
4143
return false;
4244
}
4345
return true;

Diff for: lib/coek/coek/compact/coek_sets.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,21 @@ ConcreteSet SetOf(const std::initializer_list<int>& arg);
270270
// ConcreteSet SetOf(const std::initializer_list<std::string>& arg);
271271

272272
ConcreteSet RangeSet(int start, int stop, int step = 1);
273+
274+
template <typename StartType>
275+
ConcreteSet RangeSet(const StartType& start, const Expression& stop, int step = 1)
276+
{
277+
int stop_ = static_cast<int>(stop.value());
278+
return RangeSet(start, stop_, step);
279+
}
280+
281+
template <typename StopType>
282+
ConcreteSet RangeSet(const Expression& start, const StopType& stop, int step = 1)
283+
{
284+
int start_ = static_cast<int>(start.value());
285+
return RangeSet(start_, stop, step);
286+
}
287+
273288
// ConcreteSet RangeSet(double start, double stop, double step=1.0);
274289

275290
} // namespace coek

Diff for: lib/coek/coek/compact/expression_sequence.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,11 @@ Expression Sum(const SequenceContext& context, const Expression& expr)
213213
return ans;
214214
}
215215

216+
Expression Sum(const Expression& expr, const SequenceContext& context)
217+
{
218+
ExpressionSequence seq(context, expr);
219+
Expression ans(CREATE_POINTER(SumExpressionTerm, seq));
220+
return ans;
221+
}
222+
216223
} // namespace coek

Diff for: lib/coek/coek/compact/expression_sequence.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ class ExpressionSequence {
4949
};
5050

5151
Expression Sum(const SequenceContext& context, const Expression& expr);
52+
Expression Sum(const Expression& expr, const SequenceContext& context);
53+
5254
} // namespace coek

Diff for: lib/coek/coek/util/DataPortal.hpp

+31-31
Original file line numberDiff line numberDiff line change
@@ -218,26 +218,26 @@ template <size_t N, typename... Ts>
218218
using NthTypeOf = typename std::tuple_element<N, std::tuple<Ts...>>::type;
219219

220220
template <typename TupleT, typename... ARGTYPES, std::size_t... Indices>
221-
auto vector_to_tuple_helper(const TupleT& v, std::index_sequence<Indices...>)
221+
inline auto vector_to_tuple_helper(const TupleT& v, std::index_sequence<Indices...>)
222222
{
223223
return std::make_tuple(std::get<NthTypeOf<Indices, ARGTYPES...>>(v[Indices])...);
224224
}
225225

226226
template <typename TupleT, typename... ARGTYPES>
227-
std::tuple<ARGTYPES...> DataPortalRepn::convert_to_tuple(const TupleT& v) const
227+
inline std::tuple<ARGTYPES...> DataPortalRepn::convert_to_tuple(const TupleT& v) const
228228
{
229229
return vector_to_tuple_helper<TupleT, ARGTYPES...>(
230230
v, std::make_index_sequence<sizeof...(ARGTYPES)>());
231231
}
232232

233233
template <typename TupleT, typename... ARGTYPES, std::size_t... Indices>
234-
TupleT tuple_to_vector_helper(const std::tuple<ARGTYPES...>& v, std::index_sequence<Indices...>)
234+
inline TupleT tuple_to_vector_helper(const std::tuple<ARGTYPES...>& v, std::index_sequence<Indices...>)
235235
{
236236
return TupleT{std::get<Indices>(v)...};
237237
}
238238

239239
template <typename TupleT, typename... ARGTYPES>
240-
TupleT DataPortalRepn::convert_from_tuple(const std::tuple<ARGTYPES...>& v) const
240+
inline TupleT DataPortalRepn::convert_from_tuple(const std::tuple<ARGTYPES...>& v) const
241241
{
242242
return tuple_to_vector_helper<TupleT, ARGTYPES...>(
243243
v, std::make_index_sequence<sizeof...(ARGTYPES)>());
@@ -263,7 +263,7 @@ inline std::string type_name<double>()
263263

264264
// Set data
265265
template <typename ValueType>
266-
bool DataPortalRepn::get(const std::string& name, std::set<ValueType>& data) const
266+
inline bool DataPortalRepn::get(const std::string& name, std::set<ValueType>& data) const
267267
{
268268
auto it = set_data.find(name);
269269
if (it == set_data.end())
@@ -278,7 +278,7 @@ bool DataPortalRepn::get(const std::string& name, std::set<ValueType>& data) con
278278

279279
// Set<tuple<ARGTYPES ...>> data
280280
template <typename... ARGTYPES>
281-
bool DataPortalRepn::get(const std::string& name, std::set<std::tuple<ARGTYPES...>>& data) const
281+
inline bool DataPortalRepn::get(const std::string& name, std::set<std::tuple<ARGTYPES...>>& data) const
282282
{
283283
auto it = set_data.find(name);
284284
if (it == set_data.end())
@@ -297,7 +297,7 @@ bool DataPortalRepn::get(const std::string& name, std::set<std::tuple<ARGTYPES..
297297
// Indexed set of simple data, with simple indices
298298
// Map<KeyType, Set<SetType>>
299299
template <typename KeyType, typename SetType>
300-
typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_tuple<SetType>::value, bool>::type
300+
inline typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_tuple<SetType>::value, bool>::type
301301
DataPortalRepn::get(const std::string& name, std::map<KeyType, std::set<SetType>>& data) const
302302
{
303303
auto it = indexed_set_data.find(name);
@@ -318,7 +318,7 @@ DataPortalRepn::get(const std::string& name, std::map<KeyType, std::set<SetType>
318318
// Indexed set of simple data, with tuple indices
319319
// Map<tuple<KEYTYPES...>, Set<SetType>>
320320
template <typename SetType, typename... KEYTYPES>
321-
typename std::enable_if<!is_std_tuple<SetType>::value, bool>::type DataPortalRepn::get(
321+
inline typename std::enable_if<!is_std_tuple<SetType>::value, bool>::type DataPortalRepn::get(
322322
const std::string& name, std::map<std::tuple<KEYTYPES...>, std::set<SetType>>& data) const
323323
{
324324
auto it = indexed_set_data.find(name);
@@ -340,7 +340,7 @@ typename std::enable_if<!is_std_tuple<SetType>::value, bool>::type DataPortalRep
340340
// Indexed set of tuple data, with simple indices
341341
// Map<KeyType, Set<std::tuple<SETTYPES...>>>
342342
template <typename KeyType, typename... SETTYPES>
343-
typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::get(
343+
inline typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::get(
344344
const std::string& name, std::map<KeyType, std::set<std::tuple<SETTYPES...>>>& data) const
345345
{
346346
auto it = indexed_set_data.find(name);
@@ -367,7 +367,7 @@ typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRep
367367
// Indexed set of tuple data, with tuple indices
368368
// Map<std::tuple<KEYTYPES...>, Set<std::tuple<SETTYPES...>>>
369369
template <typename... KEYTYPES, typename... SETTYPES>
370-
bool DataPortalRepn::get(
370+
inline bool DataPortalRepn::get(
371371
const std::string& name,
372372
std::map<std::tuple<KEYTYPES...>, std::set<std::tuple<SETTYPES...>>>& data) const
373373
{
@@ -395,8 +395,8 @@ bool DataPortalRepn::get(
395395
// Parameter data
396396
// TYPE
397397
template <typename TYPE>
398-
typename std::enable_if<
399-
!is_std_map<TYPE>::value && !is_std_set<TYPE>::value && !is_std_tuple<TYPE>::value, bool>::type
398+
inline typename std::enable_if<
399+
!is_std_map<TYPE>::value && !is_std_set<TYPE>::value && !is_std_tuple<TYPE>::value, bool>::type
400400
DataPortalRepn::get(const std::string& name, TYPE& data) const
401401
{
402402
auto it = parameter_data.find(name);
@@ -411,7 +411,7 @@ DataPortalRepn::get(const std::string& name, TYPE& data) const
411411
}
412412

413413
template <>
414-
bool DataPortalRepn::get(const std::string& name, double& data) const
414+
inline bool DataPortalRepn::get(const std::string& name, double& data) const
415415
{
416416
auto it = parameter_data.find(name);
417417
if (it == parameter_data.end())
@@ -429,7 +429,7 @@ bool DataPortalRepn::get(const std::string& name, double& data) const
429429

430430
// Tuple<VALUETYPES...>
431431
template <typename... VALUETYPES>
432-
bool DataPortalRepn::get(const std::string& name, std::tuple<VALUETYPES...>& data) const
432+
inline bool DataPortalRepn::get(const std::string& name, std::tuple<VALUETYPES...>& data) const
433433
{
434434
auto it = parameter_data.find(name);
435435
if (it == parameter_data.end())
@@ -445,7 +445,7 @@ bool DataPortalRepn::get(const std::string& name, std::tuple<VALUETYPES...>& dat
445445
// Indexed parameter data with simple indices
446446
// Map<Key,Value> - Indexed parameter data
447447
template <typename KeyType, typename ValueType>
448-
typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_set<ValueType>::value
448+
inline typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_set<ValueType>::value
449449
&& !is_std_tuple<ValueType>::value,
450450
bool>::type
451451
DataPortalRepn::get(const std::string& name, std::map<KeyType, ValueType>& data) const
@@ -467,7 +467,7 @@ DataPortalRepn::get(const std::string& name, std::map<KeyType, ValueType>& data)
467467
// Indexed parameter data with tuple indices
468468
// Map<tuple<KEYTYPES...>,Value> - Indexed parameter data
469469
template <typename ValueType, typename... KEYTYPES>
470-
typename std::enable_if<!is_std_set<ValueType>::value && !is_std_tuple<ValueType>::value,
470+
inline typename std::enable_if<!is_std_set<ValueType>::value && !is_std_tuple<ValueType>::value,
471471
bool>::type
472472
DataPortalRepn::get(const std::string& name,
473473
std::map<std::tuple<KEYTYPES...>, ValueType>& data) const
@@ -490,7 +490,7 @@ DataPortalRepn::get(const std::string& name,
490490
// Indexed parameter data
491491
// Map<KeyType,tuple<VALUETYPES...>> - Indexed parameter data
492492
template <typename KeyType, typename... VALUETYPES>
493-
typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::get(
493+
inline typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::get(
494494
const std::string& name, std::map<KeyType, std::tuple<VALUETYPES...>>& data) const
495495
{
496496
auto it = indexed_parameter_data.find(name);
@@ -512,7 +512,7 @@ typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRep
512512
// Indexed parameter data with tuple indices
513513
// Map<tuple<KEYTYPES...>,tuple<VALUETYPES...>> - Indexed parameter data
514514
template <typename... KEYTYPES, typename... VALUETYPES>
515-
bool DataPortalRepn::get(const std::string& name,
515+
inline bool DataPortalRepn::get(const std::string& name,
516516
std::map<std::tuple<KEYTYPES...>, std::tuple<VALUETYPES...>>& data) const
517517
{
518518
auto it = indexed_parameter_data.find(name);
@@ -537,15 +537,15 @@ bool DataPortalRepn::get(const std::string& name,
537537

538538
// Set data
539539
template <typename ValueType>
540-
bool DataPortalRepn::put(const std::string& name, const std::set<ValueType>& data)
540+
inline bool DataPortalRepn::put(const std::string& name, const std::set<ValueType>& data)
541541
{
542542
set_data[name] = data;
543543
return true;
544544
}
545545

546546
// Set<tuple<ARGTYPES ...>> data
547547
template <typename... ARGTYPES>
548-
bool DataPortalRepn::put(const std::string& name, const std::set<std::tuple<ARGTYPES...>>& data)
548+
inline bool DataPortalRepn::put(const std::string& name, const std::set<std::tuple<ARGTYPES...>>& data)
549549
{
550550
std::set<TupleValueType> tmp;
551551

@@ -560,7 +560,7 @@ bool DataPortalRepn::put(const std::string& name, const std::set<std::tuple<ARGT
560560
// Indexed set of simple data, with simple indices
561561
// Map<KeyType, Set<SetType>>
562562
template <typename KeyType, typename SetType>
563-
typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_tuple<SetType>::value, bool>::type
563+
inline typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_tuple<SetType>::value, bool>::type
564564
DataPortalRepn::put(const std::string& name, const std::map<KeyType, std::set<SetType>>& data)
565565
{
566566
std::map<KeyTypes, SetTypes> tmp;
@@ -575,7 +575,7 @@ DataPortalRepn::put(const std::string& name, const std::map<KeyType, std::set<Se
575575
// Indexed set of simple data, with tuple indices
576576
// Map<tuple<KEYTYPES...>, Set<SetType>>
577577
template <typename SetType, typename... KEYTYPES>
578-
typename std::enable_if<!is_std_tuple<SetType>::value, bool>::type DataPortalRepn::put(
578+
inline typename std::enable_if<!is_std_tuple<SetType>::value, bool>::type DataPortalRepn::put(
579579
const std::string& name, const std::map<std::tuple<KEYTYPES...>, std::set<SetType>>& data)
580580
{
581581
std::map<KeyTypes, SetTypes> tmp;
@@ -590,7 +590,7 @@ typename std::enable_if<!is_std_tuple<SetType>::value, bool>::type DataPortalRep
590590
// Indexed set of tuple data, with simple indices
591591
// Map<KeyType, Set<std::tuple<SETTYPES...>>>
592592
template <typename KeyType, typename... SETTYPES>
593-
typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::put(
593+
inline typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::put(
594594
const std::string& name, const std::map<KeyType, std::set<std::tuple<SETTYPES...>>>& data)
595595
{
596596
std::map<KeyTypes, SetTypes> tmp;
@@ -609,7 +609,7 @@ typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRep
609609
// Indexed set of tuple data, with tuple indices
610610
// Map<std::tuple<KEYTYPES...>, Set<std::tuple<SETTYPES...>>>
611611
template <typename... KEYTYPES, typename... SETTYPES>
612-
bool DataPortalRepn::put(
612+
inline bool DataPortalRepn::put(
613613
const std::string& name,
614614
const std::map<std::tuple<KEYTYPES...>, std::set<std::tuple<SETTYPES...>>>& data)
615615
{
@@ -629,7 +629,7 @@ bool DataPortalRepn::put(
629629

630630
// Parameter data
631631
template <typename TYPE>
632-
typename std::enable_if<
632+
inline typename std::enable_if<
633633
!is_std_map<TYPE>::value && !is_std_set<TYPE>::value && !is_std_tuple<TYPE>::value, bool>::type
634634
DataPortalRepn::put(const std::string& name, const TYPE& data)
635635
{
@@ -639,15 +639,15 @@ DataPortalRepn::put(const std::string& name, const TYPE& data)
639639
}
640640

641641
template <>
642-
bool DataPortalRepn::put(const std::string& name, const double& data)
642+
inline bool DataPortalRepn::put(const std::string& name, const double& data)
643643
{
644644
parameter_data[name] = data;
645645

646646
return true;
647647
}
648648

649649
template <typename... VALUETYPES>
650-
bool DataPortalRepn::put(const std::string& name, const std::tuple<VALUETYPES...>& data)
650+
inline bool DataPortalRepn::put(const std::string& name, const std::tuple<VALUETYPES...>& data)
651651
{
652652
parameter_data[name] = convert_from_tuple<TupleValueType, VALUETYPES...>(data);
653653

@@ -657,7 +657,7 @@ bool DataPortalRepn::put(const std::string& name, const std::tuple<VALUETYPES...
657657
// Indexed parameter data with simple indices
658658
// Map<Key,Value> - Indexed parameter data
659659
template <typename KeyType, typename ValueType>
660-
typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_set<ValueType>::value
660+
inline typename std::enable_if<!is_std_tuple<KeyType>::value && !is_std_set<ValueType>::value
661661
&& !is_std_tuple<ValueType>::value,
662662
bool>::type
663663
DataPortalRepn::put(const std::string& name, const std::map<KeyType, ValueType>& data)
@@ -674,7 +674,7 @@ DataPortalRepn::put(const std::string& name, const std::map<KeyType, ValueType>&
674674
// Indexed parameter data with tuple indices
675675
// Map<tuple<KEYTYPES...>,Value> - Indexed parameter data
676676
template <typename ValueType, typename... KEYTYPES>
677-
typename std::enable_if<!is_std_set<ValueType>::value && !is_std_tuple<ValueType>::value,
677+
inline typename std::enable_if<!is_std_set<ValueType>::value && !is_std_tuple<ValueType>::value,
678678
bool>::type
679679
DataPortalRepn::put(const std::string& name,
680680
const std::map<std::tuple<KEYTYPES...>, ValueType>& data)
@@ -691,7 +691,7 @@ DataPortalRepn::put(const std::string& name,
691691
// Indexed parameter data
692692
// Map<KeyType,tuple<VALUETYPES...>> - Indexed parameter data
693693
template <typename KeyType, typename... VALUETYPES>
694-
typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::put(
694+
inline typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRepn::put(
695695
const std::string& name, const std::map<KeyType, std::tuple<VALUETYPES...>>& data)
696696
{
697697
std::map<KeyTypes, ParameterTypes> tmp;
@@ -706,7 +706,7 @@ typename std::enable_if<!is_std_tuple<KeyType>::value, bool>::type DataPortalRep
706706
// Indexed parameter data with tuple indices
707707
// Map<tuple<KEYTYPES...>,tuple<VALUETYPES...>> - Indexed parameter data
708708
template <typename... KEYTYPES, typename... VALUETYPES>
709-
bool DataPortalRepn::put(const std::string& name,
709+
inline bool DataPortalRepn::put(const std::string& name,
710710
const std::map<std::tuple<KEYTYPES...>, std::tuple<VALUETYPES...>>& data)
711711
{
712712
std::map<KeyTypes, ParameterTypes> tmp;

0 commit comments

Comments
 (0)