16 double *rel,
double wx,
double wwNsqr);
18 double *rel,
double wx,
double wwNsqr);
19void wAdd(
int *
A,
int mons,
int kn,
int xx,
int rvar);
20void wNorm(
int *degw,
int *lpol,
int npol,
double *rel);
22 int *lpol,
int npol,
double *rel,
double *fopt,
double wNsqr,
int rvar);
24 int npol,
int mons,
double *rel,
double *fk,
double wNsqr,
int rvar);
25void wGcd(
int *
x,
int n);
31 double *rel,
double wx,
double wNsqr);
35 double *rel,
double wx,
double wNsqr)
37 int i,
j, e1, ecu, ecl, ec;
39 double gfmax, gecart, ghom, pfmax;
45 gecart = (double)0.4 + (
double)npol;
47 for (
i = 0;
i < npol;
i++)
49 ecl = ecu = e1 = *ex++;
50 for (
j = lpol[
i] - 1;
j!=0;
j--)
58 pfmax = (double)ecl / (
double)ecu;
61 pfmax = (double)e1 / (
double)ecu;
62 if (pfmax > (
double)0.5)
63 gecart -= (pfmax * pfmax);
65 gecart -= (double)0.25;
67 gfmax += (double)(ecu * ecu) * (*r++);
69 if (ghom > (
double)0.8)
72 gecart *= ((double)5.0 - ghom);
74 return (gfmax * gecart) /
pow(wx, wNsqr);
79 double *rel,
double wx,
double wNsqr)
81 int i,
j, ecl, ecu, ec;
83 double gfmax, ghom, pfmax;
90 for (
i = 0;
i < npol;
i++)
93 for (
j = lpol[
i] - 1;
j!=0 ;
j--)
101 pfmax = (double)ecl / (
double)ecu;
104 gfmax += (double)(ecu * ecu) * (*r++);
106 if (ghom > (
double)0.5)
107 gfmax *= ((
double)1.0 - (ghom * ghom)) / (double)0.75;
108 return gfmax /
pow(wx, wNsqr);
112static void wSub(
int *
A,
int mons,
int kn,
int xx,
int rvar)
116 B =
A + ((kn - 1) * mons);
117 ex =
A + (rvar * mons);
127 *ex++ -= (*
B++) * xx;
132void wAdd(
int *
A,
int mons,
int kn,
int xx,
int rvar)
136 B =
A + ((kn - 1) * mons);
137 ex =
A + (rvar * mons);
147 *ex++ += (*
B++) * xx;
153 int *lpol,
int npol,
double *rel,
double *fopt,
double wNsqr,
int rvar)
155 int a0, a, n,
xn, t, xx, y1;
156 int *
y, *degw, *xopt;
163 xn = n + 6 + (21 / n);
164 a0 = n *
sizeof(double);
171 degw =
A + (n * mons);
179 wx = pr[t-1] * (double)xx;
181 if ((y1 + n - t) <=
xn)
187 wAdd(
A, mons, t, 1, rvar);
195 wSub(
A, mons, t, xx, rvar);
207 wx = pr[t-1] * (double)xx;
211 wAdd(
A, mons, t, xx, rvar);
212 fmax = (*wFunctional)(degw, lpol, npol, rel, wx,wNsqr);
214 wSub(
A, mons, t, xx, rvar);
218 memcpy(xopt,
x + 1, a);
231 for (
i = n - 1;
i!=0 ;
i--)
237static void wEstimate(
int *
A,
int *
x,
int *lpol,
int npol,
int mons,
238double wx,
double *rel,
double *fopt,
int *s0,
int *s1,
int *s2,
double wNsqr,
int rvar)
240 int n, i1, i2, k0 = 0, k1 = 0, k2 = 0;
242 double fo1, fo2, fmax, wx1, wx2;
245 degw =
A + (n * mons);
246 fo2 = fo1 = (double)1.0e10;
247 for (i1 = n; i1!=0 ; i1--)
251 wSub(
A, mons, i1, 1, rvar);
252 wx1 = wx - wx / (double)
x[i1];
254 fmax = (*wFunctional)(degw, lpol, npol, rel, wx1,wNsqr);
260 for (i2 = i1; i2!=0 ; i2--)
264 wSub(
A, mons, i2, 1, rvar);
265 wx2 = wx1 - wx1 / (double)
x[i2];
266 fmax = (*wFunctional)(degw, lpol, npol, rel, wx2, wNsqr);
273 wAdd(
A, mons, i2, 1, rvar);
276 wAdd(
A, mons, i1, 1, rvar);
296int npol,
int mons,
double *rel,
double *fk,
double wNsqr,
int rvar)
298 int n, s0, s1, s2, *xopt;
303 fopt = *fk * (double)0.999999999999;
307 wEstimate(
A,
x, lpol, npol, mons, wx, rel, &fx, &s0, &s1, &s2, wNsqr, rvar);
326 memcpy(xopt,
x + 1, n *
sizeof(
int));
334 memcpy(xopt,
x + 1, n *
sizeof(
int));
340 wSub(
A, mons, s0, 1, rvar);
343 wSub(
A, mons, s1, 1, rvar);
344 wSub(
A, mons, s2, 1, rvar);
381 for (
i = n;
i!=0 ;
i--)
387static void wSimple(
int *
x,
int n)
389 int g,
min, c, d,
f, kopt,
k,
i;
396 for (
i = n;
i!=0 ;
i--)
410 if ((
g==0) && (
k < 4))
414 sopt = (double)1.0e10;
417 s2 = s1 = (double)0.0;
418 for(
i = n;
i!=0 ;
i--)
430 s2 += (double)
f / (
double)c;
432 s1 += (double)d / (
double)c;
436 s1 += s2 +
sqrt(s1 * s2);
437 s1 -= (double)0.01 *
sqrt((
double)
k);
444 for(
i = n;
i!=0 ;
i--)
454 if ((d!=0) && (kopt < 2 * d))
463void wNorm(
int *degw,
int *lpol,
int npol,
double *rel)
471 for (
i = 0;
i < npol;
i++)
474 for (
j = lpol[
i] - 1;
j!=0 ;
j--)
480 *r = (double)1.0 / (
double)(ecu * ecu);
Rational pow(const Rational &a, int e)
const CanonicalForm int const CFList const Variable & y
static int min(int a, int b)
gmp_float sqrt(const gmp_float &a)
#define omFreeSize(addr, size)
VAR double(* wFunctional)(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
void wFirstSearch(int *A, int *x, int mons, int *lpol, int npol, double *rel, double *fopt, double wNsqr, int rvar)
void wSecondSearch(int *A, int *x, int *lpol, int npol, int mons, double *rel, double *fk, double wNsqr, int rvar)
double wFunctionalMora(int *degw, int *lpol, int npol, double *rel, double wx, double wwNsqr)
static void wSub(int *A, int mons, int kn, int xx, int rvar)
void wNorm(int *degw, int *lpol, int npol, double *rel)
static void wEstimate(int *A, int *x, int *lpol, int npol, int mons, double wx, double *rel, double *fopt, int *s0, int *s1, int *s2, double wNsqr, int rvar)
void wAdd(int *A, int mons, int kn, int xx, int rvar)
static double wPrWeight(int *x, int n)
double wFunctionalBuch(int *degw, int *lpol, int npol, double *rel, double wx, double wwNsqr)