using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication15
{
class Lag
{
void Lagg(double ub, double step, params double[] B)
{
}
}
#region 动态规划
public static class DP
{ static int m=15;
static int[,] x_shadow=new int[m,m];
static int[] x = new int[m];
static int[,] y_shadow = new int[m,m];
static int[] y = new int[m];
static int[,] w = new int[m,m];
public static double dynamic(int n, double k, double c, double h, params int[] demand)
{
int[,] Dmd = new int[n + 1, n + 1];
int[,] inv = new int[n + 1, n + 1];
double[,] cost = new double[n + 1, n + 1];
double[,] cost_trans = new double[n + 1, n + 1];
double[][] cost_copy = new double[n + 1][];
double[,] cost_min = new double[n + 1, n + 1];
double[,] cost_p = new double[n + 1, n + 1];
double[,] cost_v = new double[n + 1, n + 1];
double[,] Cost_v = new double[n + 1, n + 1];
double[] min_cost = new double[n + 1];
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
Dmd[i, j] = Dmd[i, j - 1] + demand[j];
//Console.WriteLine("Dmd [{0},{1}],{2}", i, j, Dmd[i, j]);
// Console.WriteLine("......");
}
}
//cost_p
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
cost_p[i, j] = k + c * Dmd[i, j];
// Console.WriteLine(" cost_p [{0},{1}],{2}", i, j, cost_p[i, j]);
// Console.WriteLine("......");
}
}
//inventory upper triangle cost_v
for (int i = 2; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
inv[i - 1, j] = Dmd[i, j];
cost_v[i - 1, j] = h * inv[i - 1, j];
// Console.WriteLine("inv: [{0},{1}],{2},cost_inv: [{0},{1}],{3}", i - 1, j, inv[i - 1, j], cost_v[i - 1, j]);
// Console.WriteLine("......");
}
//Console.WriteLine("......");
}
// Cost_v
for (int i = 1; i <= n - 1; i++)
{
for (int j = 1; j <= n; j++)
{
for (int q = i; q <= n; q++)
{
Cost_v[i, j] += cost_v[q, j];
}
// Console.WriteLine("Cost_v: [{0},{1}],{2},cost_v: [{0},{1}],{3}", i, j, Cost_v[i, j], cost_v[i, j]);
}
}
//cost
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cost[i, j] += Cost_v[i, j] + cost_p[i, j];
// Console.WriteLine("cost: [{0},{1}],{2},", i, j, cost[i, j]);
}
}
//cost_copy
for (int i = 1; i <= n; i++)
{
cost_copy[i - 1] = new double[i];
for (int j = 1; j <= i; j++)
{
if (j == 1)
{
cost_copy[i - 1][j - 1] = cost[j, i];
}
else
{
cost_copy[i - 1][j - 1] = cost_copy[j - 2].Min() + cost[j, i];
}
//Console.WriteLine(" cost_copy: [{0}][{1}],{2} ", i, j, cost_copy[i - 1][j - 1]);
}
}
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
if (cost_copy[i - 1][j - 1] == cost_copy[i-1].Min())
{
i = j;
y[ j] = 1;
Console.WriteLine(" y [{0}]: {1} ", i, y[ j]);
break;
}
}
}
double mini = cost_copy[n - 1].Min();
Console.WriteLine(" cost_copy: {0}", cost_copy[n - 1].Min());
return cost_copy[n - 1].Min();
}
}
#endregion
class Program
{
static void Main(string[] args)
{
int Product = 4;
int Period = 12;
double[] z = new double[Product];
double[] Process_time = new double[] { 0.5, 1, 2, 4 };
double[] Cost_setup = new double[] { 100, 40, 2, 800};
double[] Cost_production = new double[] { 6, 7, 3, 10 };
double[] Cost_inventory = new double[] { 2, 2, 1, 4 };
double mcost = 0;
int[][] Demand =
{
new int[]{0,3,20,5,5,18,15,2,0,18,4,6,13},
new int[] {0,3,2,5,1,4,5,5,4,3,3,2,4},
new int[]{0,6,6,6,4,4,4,2,2,2,0,0,0},
new int[]{0,2,2,2,2,2,2,3,3,3,3,3,3}
};
int[,] x = new int[Period, Product];
int[,] y = new int[Period, Product];
int[,] w = new int[Period, Product];
for (int i = 0; i < Product; i++)
{
z[i] = DP.dynamic(Period, Cost_setup[i], Cost_production[i], Cost_inventory[i], Demand[i]);
mcost += z[i];
Console.WriteLine("mcost cost: {0}", mcost);
// z += Cost_inventory[Product] * w[i, j, k] + Cost_setup[Product] * y[i, j, k] + Cost_production[Product] * x[i, j, k];
}
Console.Read();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication15
{
class Lag
{
void Lagg(double ub, double step, params double[] B)
{
}
}
#region 动态规划
public static class DP
{ static int m=15;
static int[,] x_shadow=new int[m,m];
static int[] x = new int[m];
static int[,] y_shadow = new int[m,m];
static int[] y = new int[m];
static int[,] w = new int[m,m];
public static double dynamic(int n, double k, double c, double h, params int[] demand)
{
int[,] Dmd = new int[n + 1, n + 1];
int[,] inv = new int[n + 1, n + 1];
double[,] cost = new double[n + 1, n + 1];
double[,] cost_trans = new double[n + 1, n + 1];
double[][] cost_copy = new double[n + 1][];
double[,] cost_min = new double[n + 1, n + 1];
double[,] cost_p = new double[n + 1, n + 1];
double[,] cost_v = new double[n + 1, n + 1];
double[,] Cost_v = new double[n + 1, n + 1];
double[] min_cost = new double[n + 1];
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
Dmd[i, j] = Dmd[i, j - 1] + demand[j];
//Console.WriteLine("Dmd [{0},{1}],{2}", i, j, Dmd[i, j]);
// Console.WriteLine("......");
}
}
//cost_p
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
cost_p[i, j] = k + c * Dmd[i, j];
// Console.WriteLine(" cost_p [{0},{1}],{2}", i, j, cost_p[i, j]);
// Console.WriteLine("......");
}
}
//inventory upper triangle cost_v
for (int i = 2; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
inv[i - 1, j] = Dmd[i, j];
cost_v[i - 1, j] = h * inv[i - 1, j];
// Console.WriteLine("inv: [{0},{1}],{2},cost_inv: [{0},{1}],{3}", i - 1, j, inv[i - 1, j], cost_v[i - 1, j]);
// Console.WriteLine("......");
}
//Console.WriteLine("......");
}
// Cost_v
for (int i = 1; i <= n - 1; i++)
{
for (int j = 1; j <= n; j++)
{
for (int q = i; q <= n; q++)
{
Cost_v[i, j] += cost_v[q, j];
}
// Console.WriteLine("Cost_v: [{0},{1}],{2},cost_v: [{0},{1}],{3}", i, j, Cost_v[i, j], cost_v[i, j]);
}
}
//cost
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cost[i, j] += Cost_v[i, j] + cost_p[i, j];
// Console.WriteLine("cost: [{0},{1}],{2},", i, j, cost[i, j]);
}
}
//cost_copy
for (int i = 1; i <= n; i++)
{
cost_copy[i - 1] = new double[i];
for (int j = 1; j <= i; j++)
{
if (j == 1)
{
cost_copy[i - 1][j - 1] = cost[j, i];
}
else
{
cost_copy[i - 1][j - 1] = cost_copy[j - 2].Min() + cost[j, i];
}
//Console.WriteLine(" cost_copy: [{0}][{1}],{2} ", i, j, cost_copy[i - 1][j - 1]);
}
}
for (int i = n; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
if (cost_copy[i - 1][j - 1] == cost_copy[i-1].Min())
{
i = j;
y[ j] = 1;
Console.WriteLine(" y [{0}]: {1} ", i, y[ j]);
break;
}
}
}
double mini = cost_copy[n - 1].Min();
Console.WriteLine(" cost_copy: {0}", cost_copy[n - 1].Min());
return cost_copy[n - 1].Min();
}
}
#endregion
class Program
{
static void Main(string[] args)
{
int Product = 4;
int Period = 12;
double[] z = new double[Product];
double[] Process_time = new double[] { 0.5, 1, 2, 4 };
double[] Cost_setup = new double[] { 100, 40, 2, 800};
double[] Cost_production = new double[] { 6, 7, 3, 10 };
double[] Cost_inventory = new double[] { 2, 2, 1, 4 };
double mcost = 0;
int[][] Demand =
{
new int[]{0,3,20,5,5,18,15,2,0,18,4,6,13},
new int[] {0,3,2,5,1,4,5,5,4,3,3,2,4},
new int[]{0,6,6,6,4,4,4,2,2,2,0,0,0},
new int[]{0,2,2,2,2,2,2,3,3,3,3,3,3}
};
int[,] x = new int[Period, Product];
int[,] y = new int[Period, Product];
int[,] w = new int[Period, Product];
for (int i = 0; i < Product; i++)
{
z[i] = DP.dynamic(Period, Cost_setup[i], Cost_production[i], Cost_inventory[i], Demand[i]);
mcost += z[i];
Console.WriteLine("mcost cost: {0}", mcost);
// z += Cost_inventory[Product] * w[i, j, k] + Cost_setup[Product] * y[i, j, k] + Cost_production[Product] * x[i, j, k];
}
Console.Read();
}
}
}