/* 
 * Thomas Pantzer: t_deq.cc, v0.4.7  8.6.99 16:32 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */




#include <stdio.h>
#include <math.h>

#include "copyright.h"

#include "t_deq.h"
#include "trigonom.h"




void t_deq::Init(int i, double a, t_deq *N)
{
   id = i;
   prob = a;
   next = N;
   type = e_basic;

   best = false;
   quality = 0.0;

//wirkung
   W = 0.0;
   rho = 0.0;
   Tw = 20.0;
}


double t_deq::angle_diff(double a2)
{
   return angle_difference(atan2(param[2],param[1]),a2);
}

double t_deq::Fit(double err_sum)
{
/*
   fit = exp(-err) / err_sum;
  
   if ((fit < 0.0) || (fit > 1.0))
      fprintf(stderr,"fitness (%g) nicht in [0..1]\n",fit);
       
   return fit;
*/
   fit = -err;
   return fit;	
}

char t_deq::Update(double NY, double avg_fit, double pMin)
{
   double dp,di;
   
   dp = NY * (fit - avg_fit) * prob;

   di = prob + dp; 
   
   if (di < pMin)
      {
       prob = pMin;
       return false;
      } 
   
   if (di > pMaxMax)
      {
       prob = pMaxMax;
       return false;
      } 
     
   prob += dp;
   return true;
}

void t_deq::Done(void)
{
   if (next != NULL)
      {
       next->Done();
       delete next;
       next = NULL;
      }
}


double t_deq::GetFactor(double eps, double avgfit, int num)
{
        double sgp = sigmoid(prob,30.0,0.7);
	double factor = eps * sgp;

        return factor; 
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// virtual stubs, to be overloaded
//________________________________________________
double t_deq::Error(t_vector &Df, double ds, double da_avg, double ds_avg)
{
//   double da,dd;
	fprintf(stderr,"Error(%g,%g): basic virtual method not overloaded\n",Df.x,Df.y);
	err = 1.0;
	return err;
}

void t_deq::Update(double factor, t_vector &Df, double ds, double da_avg, double ds_avg)
{
	fprintf(stderr,"Update(%g,%g,%g,%g): basic virtual method not overloaded\n",
                          factor,Df.x,Df.y,ds);
}

void t_deq::Show(t_vertex_2i *vcenter, double size_, t_deq *BP, t_deq *BF, t_deq *SE)
{
	fprintf(stderr,"Show((%d,%d),%g,0x%lx,0x%lx,0x%lx): basic virtual method not overloaded\n",
                           vcenter->x,vcenter->y,size_,(long)BP,(long)BF,(long)SE);
};


double t_deq::Angle_Drift(char reset)
{
	fprintf(stderr,"Angle_Drift(%c): basic virtual method not overloaded\n",reset);
    return 1.0;
}












/**/
/**/
/**/
/**/
/**/
/**/
/**/
/**/
/*****  End Of File  ****************************/
