⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monitor.cc

📁 遗传算法和神经网络结合
💻 CC
字号:
/*  YAKS, a Khepera simulator including a separate GA and ANN   (Genetic Algoritm, Artificial Neural Net).  Copyright (C) 2000  Johan Carlsson (johanc@ida.his.se)    This program is free software; you can redistribute it and/or  modify it under the terms of the GNU General Public License  as published by the Free Software Foundation; either version 2  of the License, or any later version.    This program is distributed in the hope that it will be useful,  but WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License for more details.    You should have received a copy of the GNU General Public License  along with this program; if not, write to the Free Software  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.*/#include "monitor.h"Monitor::Monitor(int iWW, int iWH){  nrOfWatches = 0;  display = NULL;  watch = NULL;  wH = iWH;  wW = iWW;  wW += 100; /* place for some text */  rulers = 0;  timeStep = 100;  doUpdate = 0;  color = 2;}Monitor::~Monitor(){  if(watch){    for(int i = 0;i < nrOfWatches; i++)      delete(watch[i]);    free(watch);  }}void Monitor::addWatch(const char *title, const double *value){  if(display == NULL){    watch = (Value**) realloc(watch,sizeof(Value*)*(1+nrOfWatches));    watch[nrOfWatches++] = new Value(title,value);  }}void Monitor::redefineWatch(int index, const double *value){  if(index < 0 || index > nrOfWatches){    /* do nothing */     	//fprintf(stderr,"Monitor::redefineWatch() oops index out of range %d / %d\n\n",index,nrOfWatches);     printf("Monitor::redefineWatch() oops index out of range %d / %d\n\n",index,nrOfWatches);	  }  else{    watch[index]->redefine(value);  }}void Monitor::addWatch(const char *title, const int8_t *value){  if(display == NULL){    watch = (Value**) realloc(watch,sizeof(Value*)*(1+nrOfWatches));    watch[nrOfWatches++] = new Value(title,value);  }}void Monitor::redefineWatch(int index, const int8_t *value){  if(index < 0 || index >= nrOfWatches){    /* do nothing */  }  else{    watch[index]->redefine(value);  }}void Monitor::toggleRulers(){  if(rulers)    rulers = 0;  else    rulers = 1;}void Monitor::toggleColor(){   color++;   if(color==5)     color=2;	}void Monitor::createMonitorWindow(){  int offset;  char title[12];  static int monId=0;  if(!display){    doUpdate = 0;    g_snprintf(title,12,"Monitor%d",monId++);    display = gui_window_new(wW,wH,title);    gui_window_palette_change(display,0,0xffff,0xffff,0xffff);  /* WHITE   */    gui_window_palette_change(display,1,0,0,0);                 /* BLACK   */    gui_window_palette_change(display,2,0,0,0xffff);            /* BLUE    */    gui_window_palette_change(display,3,0xffff,0,0);            /* RED     */    gui_window_palette_change(display,4,0,0xffff,0);            /* GREEN   */    gui_window_palette_change(display,5,0xffff,0xffff,0);       /* YELLOW  */    gui_window_clear(display,1);    gui_window_set_color(display,4);    offset = (wH / nrOfWatches);    for(int i=0; i < nrOfWatches; i++){      //      if(watch[i]->getDescription()) 	//tgiPuts(0,(int)(offset*i + offset / 2),watch[i]->getDescription());    }    gui_window_flush(display);    doUpdate = 1;  }}void Monitor::deleteMonitorWindow(){  if(display){    doUpdate = 0;    //     tgiDelete(display);    //    display = NULL;  }}void Monitor::toggleUpdate(){  if(doUpdate)    doUpdate = 0;  else    doUpdate = 1;}void Monitor::update(){   int monHeight;   double value;   if(display != NULL && doUpdate){     monHeight =(int)(wH / nrOfWatches);     if(timeStep > wW)       timeStep = 100;     gui_window_set_color(display,1); /* Black - Background */     gui_window_line(display,timeStep,0,timeStep,wH);         gui_window_set_color(display,color); /* Red || Blue  - Foreground */    for(int i=1; i <= nrOfWatches; i++){       value = watch[i-1]->getVal() * 0.9;       gui_window_line(display,timeStep,(gint)(monHeight*i-monHeight*value), 	      timeStep,(gint)(monHeight*i));     }     gui_window_set_color(display,5);     gui_window_line(display,timeStep+1,0,timeStep+1,wH);     if(rulers){ /* draw ruler if requested */       if(timeStep%50 == 0){	 // 	tgiSetColour(5); 	gui_window_line(display,timeStep,0,timeStep,wH);       }     }     gui_window_flush(display);     timeStep++;   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -