/// <summary> /// Records the error in reported costs that results from implementing a decision. /// </summary> /// <param name="costsys">Pointer to the CostSys object being logged</param> /// <param name="firmID">Unique identifier of the containing firm</param> /// <param name="costSysID">Identifier of the cost system</param> /// <param name="startingDecision">A binary vector indicating which products were produced</param> /// <param name="PC_B">A vector of true product costs</param> /// <param name="PC_R">A vector of reported product costs</param> /// <param name="MPE">The mean percent error between PC_B and PC_R</param> public static void LogCostSysError( CostSys costsys, int firmID, int costSysID, RowVector startingDecision, RowVector PC_B, RowVector PC_R, double MPE) { sb_CostSys_ERROR.AppendFormat( "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", firmID, costSysID, costsys.P, costsys.A, costsys.R, startingDecision.ToCSVString(false), PC_B.ToCSVString(false), PC_R.ToCSVString(false), MPE, Environment.NewLine ); }
/// <summary> /// Records the outcome of implementing a decision, observing reported costs, and /// updating the original decision. Repeats this process until a terminal outcome /// results. See remarks. /// </summary> /// <param name="costsys"></param> /// <param name="firmID"></param> /// <param name="costSysID"></param> /// <param name="startingDecision"></param> /// <param name="endingDecision"></param> /// <param name="stopCode"></param> /// <remarks>Assume the firm implements the decision startingDecision. Upon /// doing so, it will observe total resource consumption.It will then /// allocate resources to cost pools, as per the B parameter of the cost /// system, choose drivers as per the D parameter of the cost system, /// and then allocate resources to cost objects and compute reported costs. /// The reported costs are returned as PC_R. Upon observing the /// reported costs, the firm may wish to update its original decision.When /// it implements the updated decision, costs will change again.The outcome /// of this process will either be an equilibrium decision (fixed point), or /// a cycle of decisions.</remarks> public static void LogCostSysLoop( CostSys costsys, int firmID, int costSysID, RowVector startingDecision, RowVector endingDecision, CostSystemOutcomes stopCode) { sb_CostSys_LOOP.AppendFormat( "{0},{1},{2},{3},{4},{5},{6},{7},{8}", firmID, costSysID, costsys.P, costsys.A, costsys.R, startingDecision.ToCSVString(false), endingDecision.ToCSVString(false), stopCode, Environment.NewLine ); }
/// <summary> /// Writes summary information about a firm. Writes RCC and RCU vectors for /// the firm in the RESCON file. Writes info about the firm's /// products (margins, capacities, selling prices). /// </summary> /// <param name="ip">An InputParameters object.</param> /// <param name="firm">The firm object whose data will be logged.</param> /// <param name="firmID">A unique identifier for this firm</param> /// <param name="MAR">Vector of product margins. Products with /// margins >= 1 are produced.</param> /// <param name="DECT0">Vector of 0 and 1's indicating which products /// are produced.</param> /// <param name="revenue">Revenue realized when producing the benchmark product mix</param> /// <param name="totalCost">Total cost incurred when producing the benchmark product mix</param> /// <param name="benchProfit">Profit realized when producing the benchmark product mix</param> /// <param name="RCC">Vector of resource costs</param> public static void LogFirm( InputParameters ip, Firm firm, int firmID, RowVector MAR, RowVector DECT0, double revenue, double totalCost, double benchProfit, RowVector RCC) { #region Log summary information for the firm int numProdInMix = DECT0.Count(x => x == 1.0); sb_Firm_SUM.AppendFormat( "{0},{1},{2},{3},{4},{5:F2},{6:F2},{7:F2},{8},{9}", firmID, firm.G, firm.D, ip.RCP, ip.CO, revenue, totalCost, benchProfit, numProdInMix, Environment.NewLine ); #endregion #region Log resource consumption information for the firm sb_Firm_RESCON.AppendFormat( "{0},{1},{2},{3},{4},{5}", firmID, firm.G, firm.D, RCC.ToCSVString(false), firm.RCU.ToCSVString(false), Environment.NewLine ); #endregion #region Log product information for the firm #region Create rank vectors // Rank the products by value (by total profit) RowVector RANK_BY_VAL; { // Some algebra: the profit of a product is // (SP - PC_B) x QT // = (SP - SP/MAR) x (MXQ x DECT0) // = SP (1 - 1/MAR) x (MXQ x DECT0) // where all operations are element-wise var unitProfit = firm.SP.Zip(MAR, (sp, mar) => sp * (1.0 - (1.0 / mar))); var productionQty = firm.MXQ.Zip(DECT0, (mxq, dect0) => mxq * dect0); var totProfit = unitProfit.Zip(productionQty, (pi, q) => pi * q); double[] PROFIT = totProfit.ToArray(); var rank = Enumerable.Range(0, ip.CO).Select(x => (double)x); // If the product is not produced, set its rank value // to ip.CO var rank2 = rank.Zip(DECT0, (r, dect0) => (dect0 == 1.0) ? r : (double)ip.CO); double[] rank_by_val = rank2.ToArray(); Array.Sort(PROFIT, rank_by_val); Array.Reverse(rank_by_val); RANK_BY_VAL = new RowVector(rank_by_val); } // Rank the products by margin RowVector RANK_BY_MAR; { double[] rank_by_mar = Enumerable.Range(0, ip.CO).Select(x => (double)x).ToArray(); double[] mar = MAR.ToArray(); Array.Sort(mar, rank_by_mar); Array.Reverse(rank_by_mar); RANK_BY_MAR = new RowVector(rank_by_mar); } #endregion sb_Firm_PRODUCT.AppendFormat( "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}", firmID, firm.G, firm.D, MAR.ToCSVString(false), firm.MXQ.ToCSVString(true), firm.SP.ToCSVString(false), DECT0.ToCSVString(true), RANK_BY_VAL.ToCSVString(true), RANK_BY_MAR.ToCSVString(true), Environment.NewLine ); #endregion }