1
// Copyright (C) 2005 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2005-04-01
12
using namespace dolfin;
14
/// Base class for economies
16
class Economy : public Homotopy
20
Economy(unsigned int m, unsigned int n) :
21
Homotopy(n), m(m), n(n), a(0), w(0),
22
tmp0(0), tmp1(0), tmp2(0), tmp3(0)
26
for (unsigned int i = 0; i < m; i++)
30
for (unsigned int j = 0; j < n; j++)
32
a[i][j] = dolfin::rand();
33
w[i][j] = dolfin::rand();
40
for (unsigned int i = 0; i < m; i++)
48
if ( tmp0 ) delete [] tmp0;
49
if ( tmp1 ) delete [] tmp1;
50
if ( tmp2 ) delete [] tmp2;
51
if ( tmp3 ) delete [] tmp3;
56
cout << "Trader preferences:" << endl;
57
for (unsigned int i = 0; i < m; i++)
59
cout << " trader " << i << ":";
60
for (unsigned int j = 0; j < n; j++)
61
cout << " " << a[i][j];
65
cout << "Initial endowments:" << endl;
66
for (unsigned int i = 0; i < m; i++)
68
cout << " trader " << i << ":";
69
for (unsigned int j = 0; j < n; j++)
70
cout << " " << w[i][j];
81
// Matrix of traders' preferences
84
// Matrix of traders' initial endowments
89
// Compute sum of elements
90
complex sum(const complex x[]) const
93
for (unsigned int j = 0; j < n; j++)
98
// Compute sum of elements
99
complex bsum(const complex x[], unsigned int b) const
102
for (unsigned int j = 0; j < n; j++)
103
sum += std::pow(x[j], b);
107
// Compute scalar product x . y
108
complex dot(const real x[], const complex y[]) const
111
for (unsigned int j = 0; j < n; j++)
116
// Compute special scalar product x . y.^b
117
complex bdot(const real x[], const complex y[], unsigned int b) const
120
for (unsigned int j = 0; j < n; j++)
121
sum += x[j] * std::pow(y[j], b);
125
// Compute special scalar product x . y.^b
126
complex bdot(const real x[], const complex y[], real b) const
129
for (unsigned int j = 0; j < n; j++)
130
sum += x[j] * std::pow(y[j], b);
134
// Compute special scalar product x . y.^b
135
complex bdot(const complex x[], const complex y[], unsigned int b) const
138
for (unsigned int j = 0; j < n; j++)
139
sum += x[j] * std::pow(y[j], b);
143
// Compute special scalar product x . y. z^b
144
complex bdot(const real x[], const complex y[], const complex z[], unsigned int b) const
147
for (unsigned int j = 0; j < n; j++)
148
sum += x[j] * y[j] * std::pow(z[j], b);
152
// Compute special scalar product x . y. z^b
153
complex bdot(const real x[], const complex y[], const complex z[], real b) const
156
for (unsigned int j = 0; j < n; j++)
157
sum += x[j] * y[j] * std::pow(z[j], b);
162
void disp(const real x[], const char* name)
164
dolfin::cout << name << " = [";
165
for (unsigned int j = 0; j < n; j++)
166
dolfin::cout << x[j] << " ";
167
dolfin::cout << "]" << endl;
171
void disp(const complex z[], const char* name)
173
dolfin::cout << name << " = [";
174
for (unsigned int j = 0; j < n; j++)
175
dolfin::cout << z[j] << " ";
176
dolfin::cout << "]" << endl;
179
// Initialize temporary storage for scalar products
180
void init(complex** tmp)
182
*tmp = new complex[m];
183
for (unsigned int i = 0; i < m; i++)
187
complex* tmp0; // Temporary storage for scalar products
188
complex* tmp1; // Temporary storage for scalar products
189
complex* tmp2; // Temporary storage for scalar products
190
complex* tmp3; // Temporary storage for scalar products