Problem Module

API Reference

The base components define foundational functionality of the Problem class for maintaining continuity.

Base Components

Problem.h

struct infraRank
#include <Problem.h>

A struct that calls the infraRank function to store the ID and realization of an infrastructure.

Public Functions

inline infraRank(int id, double xreal)

Public Members

int id
double xreal
struct by_xreal
#include <Problem.h>

A struct that intializes a boolean operator to compare the infraRank of two infrastructure objects.

Public Functions

inline bool operator()(const infraRank &ir1, const infraRank &ir2)
class Problem
#include <Problem.h>

The Problem class represents the basic structure of a water management and planning problem.

Created by Bernardo on 11/24/2017.

Subclassed by PaperTestProblem, Triangle

Public Functions

Problem(unsigned long n_weeks)

Constructs a new Problem object. Unset the seed for the random number generator for the reservoir objects. NOTE: Unclear what this does; need to see if can delete.

Parameters:

n_weeks – The number of weeks to simulate.

virtual ~Problem()

Destructor for the Problem object.

virtual int functionEvaluation(double *vars, double *objs, double *consts) = 0
void setN_weeks(unsigned long n_weeks)

Sets the number of weeks over which to simulate the problem.

Parameters:

n_weeks – An integer indicating the number of simulation weeks.

void setSol_number(unsigned long sol_number)

Sets the row of the decision variables of the solution (the solution number) to simulate.

Parameters:

sol_number – An unsigned long integer indicating the row of the decision variables to simulate.

void setIODirectory(const string &io_directory)

Sets the input/output directory for the problem.

Parameters:

io_directory – A const reference to the string containing the input/output directory for the problem.

void setOutputSubDirectory(const string &output_sub_directory_path)

Set the output subdirectory path for the problem.

Parameters:

output_sub_directory_path – A string containing the output subdirectory path.

const vector<double> &getObjectives() const

Gets the values of all the objectives for the current solution.

Returns:

const vector<double>&

vector<double> calculateAndPrintObjectives(bool print_files)

Calculates the objectives for the current solution. Prints them to a file if indicated as such.

Parameters:

print_files – Boolean flag to indicate if the output files should be printed.

Returns:

vector<double> The calculated objectives for each utility.

void setRDMOptimization(vector<vector<double>> &utilities_rdm, vector<vector<double>> &water_sources_rdm, vector<vector<double>> &policies_rdm)

Sets the 2D vectors of deeply uncertain factors for the problem optimization.

Parameters:
  • utilities_rdm – The reference to a 2D vector of DU factors for the short, middle, long-term and overall demand growth rate multipliers applied across all utilities //FIX: RENAME TO BETTER INDICATE RELATION TO DEMAND.

  • water_sources_rdm – The reference to a 2D vector of DU factors that scale the permitting and construction time of new water sources and the corresponding evaporation rate multipliers.

  • policies_rdm – The reference to a 2D vector of DU factors that scale the effectiveness of water use restriction policies.

void setRDMReevaluation(int rdm_no, vector<vector<double>> &utilities_rdm, vector<vector<double>> &water_sources_rdm, vector<vector<double>> &policies_rdm)

Sets the 2D vectors of deeply uncertain factors for the problem reevaluation.

Parameters:
  • rdm_no – An integer indicating the DU SOW index.

  • utilities_rdm – The reference to a 2D vector of DU factors for the short, middle, long-term and overall demand growth rate multipliers applied across all utilities

  • water_sources_rdm – The reference to a 2D vector of DU factors that scale the permitting and construction time of new water sources and the corresponding evaporation rate multipliers.

  • policies_rdm – The reference to a 2D vector of DU factors that scale the effectiveness of water use restriction policies.

void setN_threads(unsigned long n_threads)

Sets the number of threads to use in the problem optimization.

Parameters:

n_threads – An unsigned long integer indicating the number of threads to use.

void setPrint_output_files(bool print_output_files)

Sets the condition whether or not the print the problem optimization output files.

Parameters:

print_output_files – A boolean flag indicating whether or not to print the output files.

void setN_realizations(unsigned long n_realizations)

Sets the number of total realizations available. If the vector of realizations is empty, initialize and assign a vector unsigned long integers with length of n_realizations filled with zero values.

Parameters:

n_realizations – An unsigned long integer indicating the number of realizations to run.

void setRealizationsToRun(vector<unsigned long> &realizations_to_run)

Sets and limits the number of realizations to be.

Parameters:

realizations_to_run

void setEvap_inflows_suffix(const string &evap_inflows_suffix)

Sets the filename suffix for the evaporation and inflow files unique to the problem.

Parameters:

evap_inflows_suffix – A const string reference to the evaporation and inflow files suffix.

void setFname_sufix(const string &fname_sufix)

Sets the output filename suffix unique to the problem. FIXME: Need to correct function name to fname_suffix.

Parameters:

fname_sufix – A const string reference to the filename suffix.

MasterDataCollector *getMaster_data_collector()
void destroyDataCollector()

If the master_data_collector object is not null, delete it. Then assign it to a nullptr. FIXME: better to rename “deleteDataCollector”?

void printTimeSeriesAndPathways(bool plot_time_series = true)

Prints the timeseries of infrastructure pathways to output folder. Prints utilities, water sources, and policies’ time series if indicated as such.

Parameters:

plot_time_series – Boolean indicator to print the time series of utilities, water sources, and policies.

void setRofTables(unsigned long n_realizations, string rof_tables_directory)

Read and load pre-computed ROF tables. Also prints the time taken to load the tables.

Parameters:
  • n_realizations – An integer indicating the number of realizations.

  • rof_tables_directory – A string containing the directory path for the ROF tables.

void setImport_export_rof_tables(int import_export_rof_tables, string rof_tables_directory)

Takes the -C flag from main.cpp to indicate the ROF table import/export/ignore option.

Parameters:
  • import_export_rof_tables – An integer indicating the ROF table import/export/ignore option. -1: Import tables, 0: Ignore tables, 1: Export tables. Throws error “The value entered is invalid” if the input is not -1, 0, or 1. If import_export_rof_tables is set to IMPORT_ROF_TABLES (-1), assign the ROF tables directory to rof_tables_directory. For all other values, create an ROF tables directory with name rof_tables_directory.

  • rof_tables_directory – A string containing the directory path for the ROF tables.

void runBootstrapRealizationThinning(int standard_solution, int n_sets, int n_bs_samples, int threads, vector<vector<int>> &realizations_to_run)

Initializes the output directory of the master data collector and performs bootstrap analysis.

Parameters:
  • standard_solution – An integer indicating the index of the standard solution.

  • n_sets – An integer indicating the number of sets to run.

  • n_bs_samples – An integer indicating the number of bootstrap samples to run.

  • threads – An integer indicating the number of threads to use.

  • realizations_to_run – A reference to the 2D vector of integers containing data for the realizations to run.

void setFormulation(unsigned long triangle_formulation)

Sets the version number of the problem formulation to use. Formulation 0: Fixed and variable JLWTP options are all considered and independently ordered. Formulation 1: Only fixed JLWTP options are considered and indepedently ordered. Formulation 2: Only variable JLWTP options are considered and indepedently ordered.

Parameters:

triangle_formulation – An unsigned long integer indicating the formulation number.

void setDemand_path_suffix(const string &dem_suf)

Sets the filename suffix for the demand files unique to the problem.

Parameters:

dem_suf – A const string reference to the demand files suffix.

void setDemand_path_subfolder(const string &dem_subfolder)

Sets the subfolder path to the demand files.

Parameters:

dem_subfolder – A const string reference to the subfolder containing the demand files.

Protected Functions

double checkAndFixInfraExpansionHighLowOrder(vector<int> *order, vector<double> *trigger, int id_low, int id_high, double capacity_low, double capacity_high)

Prioritizes or merges infrastructure low and high expansions. If the high-expansion version is prioritized (appears earlier in the list), both the capacities of the low and high expansions are combined. The lower-priority item is removed from all lists.

Parameters:
  • order – A pointer to a vector<int> object containing the construction order of infraRank objects.

  • triggers – A pointer to a vector<double> object containing the triggers that result in the construction of each corresponding infraRank vector object.

  • id_low – The ID of the low-expansion infrastructure.

  • id_high – The ID of the high-expansion infrastructure.

  • capacity_low – The capacity of the low-expansion infrastructure.

  • capacity_high – The capacity of the high-expansion infrastructure.

Returns:

double The combined capacity of the low and high expansions if the high-expansion infrastructure is prioritized. Otherwise, return the original capacity of the high-expansion infrastructure.

vector<int> vecInfraRankToVecInt(vector<infraRank> v)

Converts the vector of infraRank objects to a vector of integers.

Parameters:

v – A vector of infraRank objects.

Returns:

vector<int> A vector of integers denoting each infrastructure’s rank (from earliest to last built) after optimization.

Protected Attributes

unsigned long n_realizations

An unsigned long integer indicating the number of realizations to simulate.

unsigned long n_weeks

An unsigned long integer indicating the number of weeks to simulate.

unsigned long solution_no

An unsigned long integer indicating the row of the decision variables to simulate.

unsigned long n_threads

An unsigned long integer indicating the number of threads to use in the optimization.

int n_utilities = NON_INITIALIZED

An integer indicating the number of utilities in the problem.

string io_directory

A string containing the input/output directory for the problem.

string output_sub_directory

A string containing the output subdirectory path for the problem.

string fname_sufix

A string containing the output filename suffix unique to the problem. FIXME: Need to correct variable name to fname_suffix.

string evap_inflows_suffix

A string containing the filename suffix for the evaporation and inflow files unique to the problem.

string demand_path_suffix

A string containing the filename suffix for the demand files unique to the problem.

string demand_path_subfolder

A srting containing the filename for the demand files subfolder.

string rof_tables_directory

A string containing the directory to the ROF tables.

vector<unsigned long> realizations_to_run

A vector of unsigned long integers containing the indices realizations to run.

MasterDataCollector *master_data_collector = nullptr

A pointer to the MasterDataCollector object.

vector<double> objectives

A vector of doubles containing the objective values for the problem.

bool print_output_files = true

A boolean flag indicating whether or not to print the output files.

int rdm_no = NON_INITIALIZED

An integer indicating the DU SOW index.

int import_export_rof_tables

An integer indicating the ROF table import/export/ignore option. -1: Import tables, 0: Ignore tables, 1: Export tables.

double table_gen_storage_multiplier

A double indicating the multiplier for the table generation storage.

vector<vector<double>> utilities_rdm

A 2D vector of doubles storing the DU multipliers for all utilities’ demand growth rates.

vector<vector<double>> water_sources_rdm

A 2D vector of doubles storing the DU multipliers for all water sources’ permitting and construction times.

vector<vector<double>> policies_rdm

A 2D vector of doubles storing the DU multipliers for all utilities’ water restriction policy effectiveness.

vector<vector<Matrix2D<double>>> rof_tables

A 2D vector of matrices storing the ROF tables for all utilities across all realizations.

unsigned long formulation

An unsigned long flag indicating which problem formulation to run.