C# Client Library
A C# Client Library for the AnalyzeRe REST API
OptimizationView.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Runtime.Serialization;
4 
6 using AnalyzeRe.APITypes;
8 using AnalyzeRe.Rest;
9 
10 namespace AnalyzeRe.Optimization
11 {
14  {
15  #region APIResource Interface Members
16  public static readonly string CLASS_COLLECTION_NAME = "optimization_views";
18 
20  [IgnoreDataMember]
21  public override string collection_name => CLASS_COLLECTION_NAME;
22  #endregion APIResource Interface Members
23 
24  #region Public Properties
25  [DataMember(Order = 12)]
27  [GreaterThan(1, true)]
28  [LessThan(10000, true)]
29  public int iterations { get; set; }
30 
32  [DataMember(Order = 13)]
33  [GreaterThan(1, true)]
34  [LessThan(10000, true)]
35  public int population_size { get; set; }
36 
38  [DataMember(Order = 14)]
39  [NotNull]
40  public IReference<AnalysisProfile> analysis_profile { get; set; }
41 
43  [DataMember(Order = 15)]
44  [NotNull]
45  [NotEmpty]
46  public List<DomainEntry> domains { get; set; }
47 
50  [DataMember(Order = 16)]
51  [NotNull]
52  [NotEmpty]
53  public Dictionary<string, object> custom_parameters { get; set; }
54 
57  [DataMember(Order = 17)]
59  public string target_currency { get; set; }
60 
61  #region Endpoints and Sub-Resources
62  #region Private Fields
63  private Candidates _candidates;
65 
67  private DataSubResource _csv;
68 
70  private SubResource<OptimizationResult> _initialPortfolioResult;
71 
73  private SubResource<SensitivityAnalysis> _sensitivityAnalysis;
74  #endregion Private Fields
75 
79  [IgnoreDataMember]
80  public Candidates candidates => _candidates ?? (_candidates = new Candidates(this));
81 
84  [IgnoreDataMember]
85  public DataSubResource csv => _csv ?? (_csv = new DataSubResource(this, "csv"));
86 
91  [IgnoreDataMember]
92  public SubResource<OptimizationResult> initial_portfolio_result => _initialPortfolioResult ??
93  (_initialPortfolioResult = new SubResource<OptimizationResult>(this, "initial_portfolio_metrics"));
94 
97  [IgnoreDataMember]
98  public SubResource<SensitivityAnalysis> sensitivity_analysis => _sensitivityAnalysis ??
99  (_sensitivityAnalysis = new SubResource<SensitivityAnalysis>(this, "sensitivity_analysis"));
100  #endregion Endpoints and Sub-Resources
101 
102  #region Deprecated
103  [Obsolete("2018-04-23: The initial_portfolio_metrics attribute is deprecated, " +
107  "please use initial_portfolio_result instead.")]
108  [DataMember(Order = 18)]
110  public Dictionary<string, double> initial_portfolio_metrics { get; set; }
111 
114  [IgnoreDataMember]
115  [Obsolete("2018-04-23: This endpoint is being deprecated because it isn't scalable. " +
116  "The preferred method is now to paginate the /candidates/ endpoint or to " +
117  "download the entire results set as a .csv file via the /csv/ endpoint.")]
119  {
120  DefaultTimeout = API.DefaultRequestTimeoutCollections
121  };
122  #endregion Deprecated
123  #endregion Public Properties
124 
125  #region Constructor
126  public OptimizationView()
128  {
129  domains = new List<DomainEntry>();
130  custom_parameters = new Dictionary<string, object>();
131  }
132 
134  protected override void AfterMembersCloned(APIType _)
135  {
136  base.AfterMembersCloned(_);
137  _candidates = null;
138  _csv = null;
139  _initialPortfolioResult = null;
140  _sensitivityAnalysis = null;
141  }
142  #endregion Constructor
143 
144  #region Public Methods
145  public OptimizationResult GetInitialPortfolioMetrics(int? timeout_ms = null) =>
150  initial_portfolio_result.Get(timeout: timeout_ms);
151 
158  public SensitivityAnalysis GetSensitivityAnalysis(IEnumerable<int> candidates = null, int? timeout_ms = null) =>
159  sensitivity_analysis.Get(candidates == null ? null : new RequestParameters()
160  .AddQueryParameter(nameof(candidates), String.Join(",", candidates)), timeout_ms);
161 
168  public Candidate GetCandidateResult(int candidateIndex, int? timeout_ms = null) =>
169  candidates.GetItem($"{candidateIndex:0}", timeout: timeout_ms);
170 
177  public PortfolioView GetCandidatePortfolioView(int candidateIndex, int? timeout_ms = null)
178  {
179  // We don't need to retrieve the actual Candidate instance to get its portfolio_view,
180  // just create one with the correct id so we can navigate to the sub-resource.
181  return new Candidate
182  {
183  optimization_view = this.ToReference(),
184  index = candidateIndex
185  }.portfolio_view.Get(timeout: timeout_ms);
186  }
187 
194  public long GetCandidateResultsCount(int? timeout_ms = null) =>
195  candidates.Count(timeout: timeout_ms);
196  #endregion Public Methods
197  }
198 }
A sub-collection of candidate results that exists off of an OptimizationView resource.
Definition: Candidates.cs:6
Helper class which makes it easier to build a set of request parameters.
Describes an additional data sub-resource available off a resource. Endpoint supports GET and PUT...
API methods / requests made available to the user.
Describes an additional sub-resource available off a resource which is not actually a property of tha...
A candidate is a potential solution to the optimization problem.
Definition: Candidate.cs:10
Base class for a StoredAPIResource that has a "status" property and corresponding "status_message" wh...
Specifies that a property is generated by the server and should not be specified on the client side d...
SubResource< PortfolioView > portfolio_view
An endpoint to request the portfolio_view that describes this candidate solution.
Definition: Candidate.cs:66
Represents the Analysis of a Portfolio
static int DefaultRequestTimeoutCollections
The default timeout used when requesting a resource collection from the server, in milliseconds...
Sensitivity analysis for the optimization view
Base interface for all reference entities.
Definition: IReference.cs:7
override void AfterMembersCloned(APIType _)
Invoked following construction if the current instance has been created using a member-wise clone of ...
Base class used by all types and resources.
Definition: APIType.cs:7
PortfolioView GetCandidatePortfolioView(int candidateIndex, int?timeout_ms=null)
Retrieves a PortfolioView corresponding to the specified candidate portfolio result, built using the analysis_profile used in this optimization run and the domain layers with modifications suggested in this candidate.
Interface for resources that reference an analysis profile.
Definition: IAPIAnalysis.cs:8
Representation of a set of Optimization Parameters.
Object to map metrics on the initial portfolio.
Attribute used to define the default value assigned to the target_currency property by the server whe...