Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kordejong committed Feb 20, 2024
1 parent c992ad0 commit b3c75ef
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,46 +460,82 @@ namespace lue::detail::integrate_and_allocate {

namespace lue {

// TODO Determine how dict values are obtained. If computed, turn them into futures to values!
// TODO Turn elements in dicts into future to elements!

template<typename Policies, Rank rank>
auto integrate_and_allocate(
Policies const& policies,
SerialRoute<policy::InputElementT<Policies, 0>, rank> const& route,
PartitionedArray<policy::InputElementT<Policies, 1>, rank> const& zone,
std::vector<
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 1>, rank> const>> const&
sdp_factors,
std::vector<
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 2>, rank> const>> const&
crop_fractions)
yield_factors,
std::vector<
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 3>, rank> const>> const&
crop_fractions,
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::InputElementT<Policies, 4>>> const&
demands,
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::InputElementT<Policies, 5>>> const&
current_production,
PartitionedArray<policy::InputElementT<Policies, 6>, rank> const& irrigated_crop_fractions)
-> std::tuple<
std::vector<PartitionedArray<policy::OutputElementT<Policies, 0>, rank>>,
std::map<policy::InputElementT<Policies, 1>, policy::OutputElementT<Policies, 1>>>
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::OutputElementT<Policies, 1>>>>
{
using RouteID = policy::InputElementT<Policies, 0>;
using ZoneElement = policy::InputElementT<Policies, 1>;
using CropFractionElement = policy::InputElementT<Policies, 2>;
using ZoneElement = RouteID;

using SDPFactorElement = policy::InputElementT<Policies, 1>;
using YieldFactorElement = policy::InputElementT<Policies, 2>;
using CropFractionElement = policy::InputElementT<Policies, 3>;
using DemandElement = policy::InputElementT<Policies, 4>;
using ProductionElement = policy::InputElementT<Policies, 5>;

static_assert(std::is_integral_v<RouteID>);
static_assert(std::is_integral_v<ZoneElement>);
static_assert(std::is_floating_point_v<SDPFactorElement>);
static_assert(std::is_floating_point_v<YieldFactorElement>);
static_assert(std::is_floating_point_v<CropFractionElement>);
static_assert(std::is_floating_point_v<DemandElement>);
static_assert(std::is_floating_point_v<ProductionElement>);

static_assert(std::is_same_v<CropFractionElement, policy::InputElementT<Policies, 6>>);
static_assert(std::is_same_v<CropFractionElement, policy::OutputElementT<Policies, 0>>);
static_assert(std::is_same_v<ProductionElement, policy::OutputElementT<Policies, 1>>);

using ProductionElement = policy::OutputElementT<Policies, 1>;
// using ProductionElement = policy::OutputElementT<Policies, 1>;

static_assert(std::is_floating_point_v<ProductionElement>);

using Route = SerialRoute<RouteID, rank>;
using RoutePartition = PartitionT2<Route>;
using RoutePartitions = PartitionsT2<Route>;

using ZoneArray = PartitionedArray<ZoneElement, rank>;
using ZonePartition = PartitionT<ZoneArray>;
using ZonePartitions = PartitionsT<ZoneArray>;
using SDPFactorArray = PartitionedArray<SDPFactorElement, rank>;
using SDPFactorPartition = PartitionT<SDPFactorArray>;
using SDPFactorPartitions = PartitionsT<SDPFactorArray>;
using SDPFactorArrays = std::vector<PartitionedArray<SDPFactorElement, rank>>;

using YieldFactorArray = PartitionedArray<YieldFactorElement, rank>;
using YieldFactorPartition = PartitionT<YieldFactorArray>;
using YieldFactorPartitions = PartitionsT<YieldFactorArray>;
using YieldFactorArrays = std::vector<PartitionedArray<YieldFactorElement, rank>>;

using CropFractionArray = PartitionedArray<CropFractionElement, rank>;
using CropFractionPartition = PartitionT<CropFractionArray>;
using CropFractionPartitions = PartitionsT<CropFractionArray>;
using CropFractionArrays = std::vector<PartitionedArray<CropFractionElement, rank>>;

using ZonalProduction = std::map<ZoneElement, ProductionElement>;

using ZonalProduction = std::map<ZoneElement, std::vector<ProductionElement>>;


// TODO Exceptions:
// - verify length of vectors is the same
// - verify number of routes, number of zones in dicts


CropFractionArrays crop_fraction_arrays{};
ZonalProduction zonal_production{};
Expand Down Expand Up @@ -588,10 +624,18 @@ namespace lue {
\
template LUE_IMAGE_LAND_OPERATION_EXPORT std::tuple< \
std::vector<PartitionedArray<policy::OutputElementT<Policies, 0>, rank>>, \
std::map<policy::InputElementT<Policies, 1>, policy::OutputElementT<Policies, 1>>> \
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::OutputElementT<Policies, 1>>>> \
integrate_and_allocate<ArgumentType<void(Policies)>, rank>( \
ArgumentType<void(Policies)> const&, \
SerialRoute<policy::InputElementT<Policies, 0>, rank> const&, \
PartitionedArray<policy::InputElementT<Policies, 1>, rank> const&, \
std::vector<std::reference_wrapper< \
PartitionedArray<policy::InputElementT<Policies, 2>, rank> const>> const&);
PartitionedArray<policy::InputElementT<Policies, 1>, rank> const>> const&, \
std::vector<std::reference_wrapper< \
PartitionedArray<policy::InputElementT<Policies, 2>, rank> const>> const&, \
std::vector<std::reference_wrapper< \
PartitionedArray<policy::InputElementT<Policies, 3>, rank> const>> const&, \
std:: \
map<policy::InputElementT<Policies, 0>, std::vector<policy::InputElementT<Policies, 4>>> const&, \
std:: \
map<policy::InputElementT<Policies, 0>, std::vector<policy::InputElementT<Policies, 5>>> const&, \
PartitionedArray<policy::InputElementT<Policies, 6>, rank> const&)
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@


namespace lue {
// Inputs:
// 0. ZoneElement: route ID
// 1. FloatingPointElement: sdp_factor
// 2. FloatingPointElement: yield_factor
// 3. FloatingPointElement: crop_fraction
// 4. FloatingPointElement: demand
// 5. FloatingPointElement: production
// 6. FloatingPointElement: irrigated_crop_fraction

// Outputs:
// 0. FloatingPointElement: crop_fraction
// 1. ...
// 2. ...

template<typename Policies, Rank rank>
auto integrate_and_allocate(
Policies const& policies,
SerialRoute<policy::InputElementT<Policies, 0>, rank> const& route,
PartitionedArray<policy::InputElementT<Policies, 1>, rank> const& zone,
SerialRoute<policy::InputElementT<Policies, 0>, rank> const& routes,
std::vector<
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 1>, rank> const>> const&
sdp_factors,
std::vector<
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 2>, rank> const>> const&
crop_fractions)
yield_factors,
std::vector<
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 3>, rank> const>> const&
crop_fractions,
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::InputElementT<Policies, 4>>> const&
demands,
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::InputElementT<Policies, 5>>> const&
current_production,
PartitionedArray<policy::InputElementT<Policies, 6>, rank> const& irrigated_crop_fractions)
-> std::tuple<
// Crop fractions
std::vector<PartitionedArray<policy::OutputElementT<Policies, 0>, rank>>,
// Zonal production
std::map<policy::InputElementT<Policies, 1>, policy::OutputElementT<Policies, 1>>>;
// Per zone and crop a single value
std::map<policy::InputElementT<Policies, 0>, std::vector<policy::OutputElementT<Policies, 1>>>>;

} // namespace lue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ namespace lue {

template<typename ZoneElement, typename FloatingPointElement>
using DefaultValuePolicies = policy::DefaultValuePolicies<
AllValuesWithinDomain<ZoneElement, ZoneElement, FloatingPointElement>,
AllValuesWithinDomain<
ZoneElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement>,
OutputElements<FloatingPointElement, FloatingPointElement>,
InputElements<ZoneElement, ZoneElement, FloatingPointElement>>;
InputElements<
ZoneElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement,
FloatingPointElement>>;

} // namespace policy::integrate_and_allocate

Expand All @@ -18,18 +32,32 @@ namespace lue {

template<typename ZoneElement, typename FloatingPointElement, Rank rank>
auto integrate_and_allocate(
SerialRoute<ZoneElement, rank> const& route,
PartitionedArray<ZoneElement, rank> const& zone,
SerialRoute<ZoneElement, rank> const& routes,
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const&
crop_fractions)
sdp_factors,
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const&
yield_factors,
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const&
crop_fractions,
std::map<ZoneElement, std::vector<FloatingPointElement>> const& demands,
std::map<ZoneElement, std::vector<FloatingPointElement>> const& current_production,
PartitionedArray<FloatingPointElement, rank> const& irrigated_crop_fractions)
-> std::tuple<
std::vector<PartitionedArray<FloatingPointElement, rank>>,
std::map<ZoneElement, FloatingPointElement>>
std::map<ZoneElement, std::vector<FloatingPointElement>>>
{
using Policies =
policy::integrate_and_allocate::DefaultValuePolicies<ZoneElement, FloatingPointElement>;

return integrate_and_allocate(Policies{}, route, zone, crop_fractions);
return integrate_and_allocate(
Policies{},
routes,
sdp_factors,
yield_factors,
crop_fractions,
demands,
current_production,
irrigated_crop_fractions);
}

} // namespace value_policies
Expand Down
19 changes: 16 additions & 3 deletions source/framework/image_land/python/src/integrate_and_allocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ namespace lue::image_land {
template<typename ZoneElement, typename FloatingPointElement, Rank rank>
auto integrate_and_allocate(
SerialRoute<ZoneElement, rank> const& route,
PartitionedArray<ZoneElement, rank> const& zone,
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const&
crop_fractions)
sdp_factors,
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const&
yield_factors,
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const&
crop_fractions,
std::map<ZoneElement, std::vector<FloatingPointElement>> const& demands,
std::map<ZoneElement, std::vector<FloatingPointElement>> const& current_production,
PartitionedArray<FloatingPointElement, rank> const& irrigated_crop_fractions)
{
return lue::value_policies::integrate_and_allocate(route, zone, crop_fractions);
return lue::value_policies::integrate_and_allocate(
route,
sdp_factors,
yield_factors,
crop_fractions,
demands,
current_production,
irrigated_crop_fractions);
}


Expand Down

0 comments on commit b3c75ef

Please sign in to comment.