24 #include "displaycontroller.h"
28 #include <QFileDialog>
29 #include <QMessageBox>
40 #pragma warning(disable:4996)
43 #define MAXFREEP 10000
47 NetworkDialog::NetworkDialog(Evonet* net, QWidget* parent, Qt::WindowFlags flags) : QWidget( parent, flags )
60 m_mainLayout =
new QVBoxLayout(
this);
65 m_toolBar =
new QToolBar(
this);
66 m_mainLayout->addWidget(m_toolBar);
69 this->enet->neuronlesions = 0;
73 rendNetwork =
new RendNetwork(
this );
74 m_mainLayout->addWidget( rendNetwork, 4 );
76 mixerDialog =
new MixerDialog( enet,
this );
77 m_mainLayout->addWidget( mixerDialog );
80 statusb =
new QLabel(
"",
this);
81 m_mainLayout->addWidget(statusb);
83 connect(rendNetwork, SIGNAL(selectedneuronsChanged()),
this, SLOT(updatetoolb()) );
87 NetworkDialog::~NetworkDialog()
122 void NetworkDialog::setNet(Evonet* n)
129 mixerDialog->setNet(enet);
132 void NetworkDialog::error(
const char *emessage)
134 QMessageBox::about(
this,
"ERROR", emessage);
137 void NetworkDialog::warning(
const char *emessage)
139 QMessageBox::about(
this,
"WARNING", emessage);
143 void NetworkDialog::createToolBars()
149 m_toolBar->addAction(openAct);
150 m_toolBar->addAction(saveAct);
152 cblockAct =
new QComboBox( m_toolBar );
153 cblockAct->addItems(QStringList() <<
"blocks list");
154 for (b=0; b < enet->net_nblocks; b++)
156 block_name(b, stblock);
157 cblockAct->addItems(QStringList() << stblock);
159 connect( cblockAct, SIGNAL(currentIndexChanged(
int)),
this, SLOT(selblock_changed(
int)) );
160 connect(
this, SIGNAL(selectedblockChanged()),
this, SLOT(updateblocktype()) );
162 m_toolBar->addWidget( cblockAct );
164 blocktypeAct =
new QComboBox( m_toolBar );
165 blocktypeAct->addItems(QStringList() <<
"block type");
166 blocktypeAct->addItems(QStringList() <<
"genetic" <<
"fixed" <<
"back-prop" );
167 connect(blocktypeAct, SIGNAL(currentIndexChanged(
int)),
this, SLOT(changeblocktype(
int)) );
168 m_toolBar->addWidget( blocktypeAct );
170 neurontypeAct =
new QComboBox( m_toolBar );
171 neurontypeAct->addItems( QStringList() <<
"neuron type");
172 neurontypeAct->addItems( QStringList() <<
"sigmoid" <<
"integrator" <<
"binary" <<
"sigmoid flat" );
173 connect( neurontypeAct, SIGNAL(currentIndexChanged(
int)),
this, SLOT(set_neurontype(
int)) );
174 m_toolBar->addWidget( neurontypeAct );
176 m_toolBar->addAction(display_labelAct);
177 m_toolBar->addAction(display_weightAct);
178 m_toolBar->addAction(display_deltaAct);
179 m_toolBar->addAction(display_biasAct);
180 m_toolBar->addAction(display_gainAct);
181 m_toolBar->addAction(set_neurondisplayAct);
182 m_toolBar->addAction(set_lesionAct);
183 m_toolBar->addAction(set_neuronbiasAct);
184 m_toolBar->addAction(set_neurongainAct);
185 m_toolBar->addAction(add_ublockAct);
186 m_toolBar->addAction(add_cblockAct);
187 m_toolBar->addAction(add_gblockAct);
188 m_toolBar->addAction(erase_Act);
191 void NetworkDialog::createActions()
195 openAct =
new QAction(QIcon(
":/evorobot/open.png"), tr(
"&Open"),
this);
198 openAct->setStatusTip(tr(
"Open a network architecture or a phenotype file"));
199 connect(openAct, SIGNAL(triggered()),
this, SLOT(open()));
201 saveAct =
new QAction(QIcon(
":/evorobot/save.png"), tr(
"&Save"),
this);
202 saveAct->setStatusTip(tr(
"Save the network architecture or the phenotype from a file"));
203 connect(saveAct, SIGNAL(triggered()),
this, SLOT(save()));
205 set_neurondisplayAct =
new QAction(QIcon(
":/evorobot/show.png"), tr(
"&Set/Unset neurons to be displayed as graph"),
this);
206 set_neurondisplayAct->setShortcut(tr(
"Ctrl+N"));
207 set_neurondisplayAct->setStatusTip(tr(
"Select/Deselect neurons to be displayed as graph"));
208 connect(set_neurondisplayAct, SIGNAL(triggered()),
this, SLOT(set_neurondisplay()));
210 set_neurongainAct =
new QAction(QIcon(
":/evorobot/gain.png"), tr(
"&Add/Remove neurons gain"),
this);
211 set_neurongainAct->setShortcut(tr(
"Ctrl+G"));
212 set_neurongainAct->setStatusTip(tr(
"Add/Remove neurons gain"));
213 connect(set_neurongainAct, SIGNAL(triggered()),
this, SLOT(set_neurongain()));
215 set_neuronbiasAct =
new QAction(QIcon(
":/evorobot/bias.png"), tr(
"&Add/Remove neurons biases"),
this);
216 set_neuronbiasAct->setShortcut(tr(
"Ctrl+B"));
217 set_neuronbiasAct->setStatusTip(tr(
"Add/Remove neurons bias"));
218 connect(set_neuronbiasAct, SIGNAL(triggered()),
this, SLOT(set_neuronbias()));
220 set_lesionAct =
new QAction(QIcon(
":/evorobot/lesion.png"), tr(
"&Lesion/Restore neurons"),
this);
221 set_lesionAct->setShortcut(tr(
"Ctrl+B"));
222 set_lesionAct->setStatusTip(tr(
"Lesion/Restore neurons"));
223 connect(set_lesionAct, SIGNAL(triggered()),
this, SLOT(set_lesion()));
225 display_labelAct =
new QAction(QIcon(
":/evorobot/label.png"), tr(
"&Display/Undisplay neuron labels"),
this);
226 display_labelAct->setShortcut(tr(
"Ctrl+L"));
227 display_labelAct->setStatusTip(tr(
"Display neuron labels"));
228 connect(display_labelAct, SIGNAL(triggered()),
this, SLOT(display_label()));
230 display_weightAct =
new QAction(QIcon(
":/evorobot/weight.png"), tr(
"&Display/Undisplay weights"),
this);
231 display_weightAct->setShortcut(tr(
"Ctrl+W"));
232 display_weightAct->setStatusTip(tr(
"Display the incoming and outcoming weight of a neuron"));
233 connect(display_weightAct, SIGNAL(triggered()),
this, SLOT(display_weight()));
235 display_deltaAct =
new QAction(QIcon(
":/evorobot/ddelta.png"), tr(
"&Display/Undisplay neurons delta"),
this);
236 display_deltaAct->setShortcut(tr(
"Ctrl+Y"));
237 display_deltaAct->setStatusTip(tr(
"Display neurons delta"));
238 connect(display_deltaAct, SIGNAL(triggered()),
this, SLOT(display_delta()));
240 display_biasAct =
new QAction(QIcon(
":/evorobot/dbias.png"), tr(
"&Display/Undisplay biases"),
this);
241 display_biasAct->setShortcut(tr(
"Ctrl+Z"));
242 display_biasAct->setStatusTip(tr(
"Display neurons biases"));
243 connect(display_biasAct, SIGNAL(triggered()),
this, SLOT(display_bias()));
245 display_gainAct =
new QAction(QIcon(
":/evorobot/dgain.png"), tr(
"&Display/Undisplay gains"),
this);
246 display_gainAct->setShortcut(tr(
"Ctrl+G"));
247 display_gainAct->setStatusTip(tr(
"Display neurons gains"));
248 connect(display_gainAct, SIGNAL(triggered()),
this, SLOT(display_gain()));
250 erase_Act =
new QAction(QIcon(
":/evorobot/erase.png"), tr(
"&Erase"),
this);
251 erase_Act->setShortcut(tr(
"Ctrl+E"));
252 erase_Act->setStatusTip(tr(
"Erase all or selected properties"));
253 connect(erase_Act, SIGNAL(triggered()),
this, SLOT(erase()));
255 add_ublockAct =
new QAction(QIcon(
":/evorobot/addublock.png"), tr(
"&Add Update Block"),
this);
256 add_ublockAct->setShortcut(tr(
"Ctrl+A"));
257 add_ublockAct->setStatusTip(tr(
"add an update block"));
258 connect(add_ublockAct, SIGNAL(triggered()),
this, SLOT(add_ublock()));
260 add_cblockAct =
new QAction(QIcon(
":/evorobot/addblock.png"), tr(
"&Add Connection Block"),
this);
261 add_cblockAct->setShortcut(tr(
"Ctrl+A"));
262 add_cblockAct->setStatusTip(tr(
"add a connection block"));
263 connect(add_cblockAct, SIGNAL(triggered()),
this, SLOT(add_cblock()));
265 add_gblockAct =
new QAction(QIcon(
":/evorobot/gainblock.png"), tr(
"&Add a gain block"),
this);
266 add_gblockAct->setShortcut(tr(
"Ctrl+G"));
267 add_gblockAct->setStatusTip(tr(
"add a gain block"));
268 connect(add_gblockAct, SIGNAL(triggered()),
this, SLOT(add_gblock()));
270 increasevAct =
new QShortcut(tr(
"+"),
this);
271 connect(increasevAct, SIGNAL(activated()),
this, SLOT(increasev()));
273 decreasevAct =
new QShortcut(tr(
"-"),
this);
274 connect(decreasevAct, SIGNAL(activated()),
this, SLOT(decreasev()));
281 int NetworkDialog::getcblock()
283 return(cblockAct->currentIndex() - 1);
289 void NetworkDialog::updatetoolb()
296 neurontypeAct->setCurrentIndex(enet->neurontype[cneuron[0]]+1);
303 void NetworkDialog::updateblocktype()
311 blocktypeAct->setCurrentIndex(enet->net_block[cb][5]+1);
318 void NetworkDialog::changeblocktype(
int t)
326 if (t > 0 && cb > 0 ) {
327 oldt = enet->net_block[cb][5];
328 enet->net_block[cb][5] = t - 1;
330 statusb->setText(QString(
"The type of the selected block has been modified"));
336 void NetworkDialog::set_neurondisplay()
350 for (i=cneuron[0]; i <= cneuron[1]; i++)
353 for (i=cneuron[0]; i <= cneuron[1]; i++)
356 if (cneuronn < 1 || cneuronn > 2)
357 warning(
"you should select one neuron or one block of neurons first");
359 statusb->setText(QString(
"Neurons to be monitored have been updated"));
362 rendNetwork->update();
366 void NetworkDialog::set_neurontype(
int t)
372 oldt = enet->neurontype[cneuron[0]];
374 enet->neurontype[cneuron[0]] = t-1;
377 for (
int i=cneuron[0]; i <= cneuron[1]; i++) {
378 enet->neurontype[i] = t-1;
381 if (cneuronn < 1 || cneuronn > 2)
382 warning(
"you should select one neuron or one block of neurons first");
384 if (oldt != enet->neurontype[cneuron[0]])
385 statusb->setText(QString(
"Neurons' type updated"));
388 rendNetwork->update();
395 void NetworkDialog::selblock_changed(
int t)
398 statusb->setText(QString(
"Block selected"));
399 emit selectedblockChanged();
400 rendNetwork->update();
404 void NetworkDialog::set_neurongain()
408 if (cneuronn < 1 || cneuronn > 2)
410 warning(
"you should select one neuron or one block of neurons first");
416 if (enet->neurongain[cneuron[0]] == 1)
418 enet->neurongain[cneuron[0]] = 0;
419 statusb->setText(QString(
"Neuron's gain eliminated"));
423 enet->neurongain[cneuron[0]] = 1;
424 statusb->setText(QString(
"Neuron's gain added"));
429 if (enet->neurongain[cneuron[0]] == 1)
431 for (i=cneuron[0]; i <= cneuron[1]; i++)
432 enet->neurongain[i] = 0;
433 statusb->setText(QString(
"Neurons' gain eliminated"));
437 for (i=cneuron[0]; i <= cneuron[1]; i++)
438 enet->neurongain[i] = 1;
439 statusb->setText(QString(
"Neurons' gain added"));
446 rendNetwork->update();
452 void NetworkDialog::set_neuronbias()
456 if (cneuronn < 1 || cneuronn > 2)
458 warning(
"you should select one neuron or one block of neurons first");
464 if (enet->neuronbias[cneuron[0]] == 1)
466 enet->neuronbias[cneuron[0]] = 0;
467 statusb->setText(QString(
"Neuron's bias eliminated"));
471 enet->neuronbias[cneuron[0]] = 1;
472 statusb->setText(QString(
"Neuron's bias added"));
477 if (enet->neuronbias[cneuron[0]] == 1)
479 for (i=cneuron[0]; i <= cneuron[1]; i++)
480 enet->neuronbias[i] = 0;
481 statusb->setText(QString(
"Neurons' bias eliminated"));
485 for (i=cneuron[0]; i <= cneuron[1]; i++)
486 enet->neuronbias[i] = 1;
487 statusb->setText(QString(
"Neurons' bias added"));
491 rendNetwork->update();
499 void NetworkDialog::set_lesion()
510 statusb->setText(QString(
"Neuron's lesioned"));
511 rendNetwork->update();
516 for(
int ls = cneuron[0]; ls <= cneuron[1]; ls++)
523 statusb->setText(QString(
"Neurons' lesioned"));
524 rendNetwork->update();
528 warning(
"you should select one neuron or one block of neurons first");
534 for (
int i = 0; i < enet->nneurons; i++)
540 statusb->setText(QString(
"Neurons un-lesioned"));
541 rendNetwork->update();
546 void NetworkDialog::display_label()
551 pseudo_activate_net();
552 statusb->setText(QString(
"Neurons labels displayed"));
553 rendNetwork->update();
560 void NetworkDialog::display_delta()
563 if (cneuronn == 1 || cneuronn == 2)
566 pseudo_activate_net();
569 statusb->setText(QString(
"Neurons' timeconstants weight displayed"));
570 rendNetwork->update();
574 warning(
"you should select one neuron or one block of neurons first");
580 void NetworkDialog::display_weight()
586 pseudo_activate_net();
587 statusb->setText(QString(
"Connections weights displayed"));
590 rendNetwork->update();
594 warning(
"you should select the receiving and sending block of neurons first (4 neurons)");
599 void NetworkDialog::display_bias()
602 if (cneuronn == 1 || cneuronn == 2)
605 pseudo_activate_net();
606 statusb->setText(QString(
"Biases weight displayed"));
607 rendNetwork->update();
612 warning(
"you should select one neuron or one block of neurons first");
618 void NetworkDialog::display_gain()
622 if (cneuronn == 1 || cneuronn == 2)
625 pseudo_activate_net();
628 statusb->setText(QString(
"Neurons' gain weight displayed"));
629 rendNetwork->update();
633 warning(
"you should select one neuron or one block of neurons first");
639 void NetworkDialog::erase()
647 cblock = getcblock();
652 enet->net_nblocks = 0;
654 cblockAct->addItems(QStringList() <<
"blocks list");
655 for(i=0;i < enet->nneurons; i++)
657 enet->neuronbias[i] = 0;
658 enet->neurontype[i] = 0;
659 enet->neurongain[i] = 0;
662 statusb->setText(QString(
"All blocks erased and neurons' properties reset"));
667 cblockAct->removeItem(cblock+1);
668 cblockAct->setCurrentIndex(0);
669 for (bb=cblock; bb < (enet->net_nblocks - 1); bb++)
670 for (ii=0; ii < 6; ii++)
671 enet->net_block[bb][ii] = enet->net_block[bb+1][ii];
673 statusb->setText(QString(
"Selected block erased"));
675 rendNetwork->update();
680 void NetworkDialog::add_ublock()
687 if (cneuronn != 1 && cneuronn != 2)
689 warning(
"you should select a a lock (2 neurons) first");
693 cblock = getcblock();
695 cblock = enet->net_nblocks;
699 for(i=enet->net_nblocks; i > cblock; i--)
700 for(ii=0; ii<6; ii++)
701 enet->net_block[i][ii] = enet->net_block[i-1][ii];
702 enet->net_block[cblock][0] = 1;
703 enet->net_block[cblock][1] = cneuron[0];
704 enet->net_block[cblock][2] = 1;
705 enet->net_block[cblock][3] = 0;
706 enet->net_block[cblock][4] = 0;
707 enet->net_block[cblock][5] = 0;
708 block_name(cblock, stblock);
709 cblockAct->insertItems(cblock+1, QStringList() << stblock);
716 for(i=enet->net_nblocks; i > cblock; i--)
717 for(ii=0; ii<6; ii++)
718 enet->net_block[i][ii] = enet->net_block[i-1][ii];
719 enet->net_block[cblock][0] = 1;
720 enet->net_block[cblock][1] = cneuron[0];
721 enet->net_block[cblock][2] = cneuron[1] - cneuron[0] + 1;
722 enet->net_block[cblock][3] = 0;
723 enet->net_block[cblock][4] = 0;
724 enet->net_block[cblock][5] = 0;
725 block_name(cblock, stblock);
726 cblockAct->insertItems(cblock+1, QStringList() << stblock);
731 cblockAct->setCurrentIndex(0);
732 statusb->setText(QString(
"Update block added"));
733 rendNetwork->update();
738 void NetworkDialog::add_cblock()
748 warning(
"you should select the receiving and sending blocks (4 neurons) first");
752 cblock = getcblock();
753 printf(
"cblock %d\n", cblock);
755 cblock = enet->net_nblocks;
760 for(i=enet->net_nblocks; i > cblock; i--)
761 for(ii=0; ii<6; ii++)
762 enet->net_block[i][ii] = enet->net_block[i-1][ii];
763 enet->net_block[cblock][0] = 0;
764 enet->net_block[cblock][1] = cneuron[0];
765 enet->net_block[cblock][2] = cneuron[1] - cneuron[0] + 1;
766 enet->net_block[cblock][3] = cneuron[2];
767 enet->net_block[cblock][4] = cneuron[3] - cneuron[2] + 1;
768 enet->net_block[cblock][5] = 0;
769 block_name(cblock, stblock);
770 cblockAct->insertItems(cblock+1, QStringList() << stblock);
775 cblockAct->setCurrentIndex(0);
776 statusb->setText(QString(
"Connection block added"));
777 rendNetwork->update();
781 void NetworkDialog::add_gblock()
788 if (cneuronn != 2 && cneuronn != 3)
790 warning(
"you should select a block (2 neurons) and eventually a third neuron first");
794 cblock = getcblock();
796 cblock = enet->net_nblocks;
802 for(i=enet->net_nblocks; i > cblock; i--)
803 for(ii=0; ii<6; ii++)
804 enet->net_block[i][ii] = enet->net_block[i-1][ii];
805 enet->net_block[cblock][0] = 2;
806 enet->net_block[cblock][1] = cneuron[0];
807 enet->net_block[cblock][2] = cneuron[1] - cneuron[0] + 1;
808 enet->net_block[cblock][3] = 0;
809 enet->net_block[cblock][4] = 0;
810 enet->net_block[cblock][5] = 0;
811 block_name(cblock, stblock);
812 cblockAct->insertItems(cblock+1, QStringList() << stblock);
819 for(i=enet->net_nblocks; i > cblock; i--)
820 for(ii=0; ii<6; ii++)
821 enet->net_block[i][ii] = enet->net_block[i-1][ii];
822 enet->net_block[cblock][0] = 3;
823 enet->net_block[cblock][1] = cneuron[0];
824 enet->net_block[cblock][2] = cneuron[1] - cneuron[0] + 1;
825 enet->net_block[cblock][3] = cneuron[2];
826 enet->net_block[cblock][4] = 0;
827 enet->net_block[cblock][5] = 0;
828 block_name(cblock, stblock);
829 cblockAct->insertItems(cblock+1, QStringList() << stblock);
834 cblockAct->setCurrentIndex(0);
835 statusb->setText(QString(
"Gain block added"));
836 rendNetwork->update();
843 void NetworkDialog::open()
851 QString fileName = QFileDialog::getOpenFileName(
this,
852 "Choose a filename to open",
857 if (fileName.endsWith(
"net"))
859 filen = fileName.toLatin1();
863 statusb->setText(QString(
"File %1 loaded").arg(filename));
866 if (fileName.endsWith(
"phe"))
868 filen = fileName.toLatin1();
872 statusb->setText(QString(
"File %1 loaded").arg(filename));
880 void NetworkDialog::save()
888 QString fileName = QFileDialog::getSaveFileName(
this,
889 "Choose a filename to save",
894 if (fileName.endsWith(
"net"))
896 filen = fileName.toLatin1();
900 statusb->setText(QString(
"File %1 saved").arg(filename));
904 if (fileName.endsWith(
"phe"))
906 filen = fileName.toLatin1();
910 statusb->setText(QString(
"File %1 saved").arg(filename));
916 void NetworkDialog::increasev()
926 pseudo_activate_net();
931 *v += ((enet->wrange * 2.0f) / 256.0f);
932 pseudo_activate_net();
933 rendNetwork->update();
940 if (pseudomode != 1 && pseudomode != 4)
942 pseudo_activate_net();
947 *v += ((enet->wrange * 2.0f) / 256.0f);
948 pseudo_activate_net();
949 rendNetwork->update();
956 void NetworkDialog::decreasev()
967 pseudo_activate_net();
972 *v -= ((enet->wrange * 2.0f) / 256.0f);
973 pseudo_activate_net();
974 rendNetwork->update();
981 if (pseudomode != 1 && pseudomode != 4)
983 pseudo_activate_net();
988 *v -= ((enet->wrange * 2.0f) / 256.0f);
989 pseudo_activate_net();
990 rendNetwork->update();
997 void NetworkDialog::block_name(
int b,
char *st)
999 switch(enet->net_block[b][0])
1002 sprintf(st,
"c) %s_%s %s_%s", enet->neuronl[enet->net_block[b][1]], enet->neuronl[enet->net_block[b][1]+enet->net_block[b][2]-1],enet->neuronl[enet->net_block[b][3]],enet->neuronl[enet->net_block[b][3]+enet->net_block[b][4]-1]);
1005 sprintf(st,
"u) %s_%s", enet->neuronl[enet->net_block[b][1]], enet->neuronl[enet->net_block[b][1]+enet->net_block[b][2]-1]);
1008 sprintf(st,
"g) %s_%s", enet->neuronl[enet->net_block[b][1]], enet->neuronl[enet->net_block[b][1]+enet->net_block[b][2]-1]);
1011 sprintf(st,
"g) %s_%s %s", enet->neuronl[enet->net_block[b][1]], enet->neuronl[enet->net_block[b][1]+enet->net_block[b][2]-1],enet->neuronl[enet->net_block[b][3]]);
1014 sprintf(st,
"undefined block type");
1026 NetworkDialog::pseudo_activate_net()
1062 for(i=0;i < enet->nneurons;i++)
1063 strcpy(neuroncl[i],enet->neuronl[i]);
1069 for(i=0;i < enet->nneurons;i++)
1071 if (enet->neurongain[i] == 1)
1073 if (dgain > 0 && ((cneuronn == 1 && i == cneuron[0]) || (cneuronn == 2 && i >= cneuron[0] && i <= cneuron[1])))
1075 gain = (fabs((
double) *p) / enet->wrange) * enet->grange;
1076 sprintf(neuroncl[i],
"%.1f",gain);
1086 for(i=0;i < enet->nneurons;i++)
1088 if (enet->neuronbias[i] == 1)
1090 if (dbias > 0 && ((cneuronn == 1 && i == cneuron[0]) || (cneuronn == 2 && i >= cneuron[0] && i <= cneuron[1])))
1092 bias = (fabs((
double) *p) / enet->wrange) * enet->brange;
1093 sprintf(neuroncl[i],
"%.1f",bias);
1103 for (b=0; b < enet->net_nblocks; b++)
1106 if (enet->net_block[b][0] == 0)
1108 for(t=enet->net_block[b][1]; t < enet->net_block[b][1] + enet->net_block[b][2];t++)
1109 for(i=enet->net_block[b][3]; i < enet->net_block[b][3] + enet->net_block[b][4];i++)
1112 if (dweight == 1 && cneuronn == 4 && (t >= cneuron[0] && t <= cneuron[1]) && (i >= cneuron[2] && i <= cneuron[3]))
1115 if (cneuron[0] == cneuron[1])
1116 sprintf(neuroncl[i],
"%.1f",*p);
1125 if (enet->net_block[b][0] == 1)
1127 for(t=enet->net_block[b][1]; t < (enet->net_block[b][1] + enet->net_block[b][2]); t++)
1130 if (enet->neurontype[t] != 1)
1137 delta = (float) (fabs((
double) *p) / enet->wrange);
1138 if (ddelta > 0 && ((cneuronn == 1 && t == cneuron[0]) || (cneuronn == 2 && t >= cneuron[0] && t <= cneuron[1])))
1140 sprintf(neuroncl[t],
"%.1f",delta);
1157 void NetworkDialog::openMixer()
1161 mixerDialog->setUpMixer();
1162 mixerDialog->show();
1163 rendNetwork->update();
1173 RendNetwork::RendNetwork( NetworkDialog* networkDialog, QWidget *parent)
1177 antialiased =
false;
1178 pixmap.load(
":/evorobot/qt-logo.png");
1180 setBackgroundRole(QPalette::Base);
1181 this->networkDialog = networkDialog;
1187 QSize RendNetwork::minimumSizeHint()
const
1189 return QSize(250, 250);
1192 QSize RendNetwork::sizeHint()
const
1194 return QSize(550, 500);
1197 void RendNetwork::setShape(Shape shape)
1199 this->shape = shape;
1203 void RendNetwork::setPen(
const QPen &pen)
1211 void RendNetwork::setBrush(
const QBrush &brush)
1213 this->brush = brush;
1217 void RendNetwork::setAntialiased(
bool antialiased)
1219 this->antialiased = antialiased;
1223 void RendNetwork::setTransformed(
bool transformed)
1225 this->transformed = transformed;
1230 void RendNetwork::paintEvent(QPaintEvent *)
1241 int selectedneurons[2];
1242 QPainter painter(
this);
1244 QRect labelxy(0,0,30,20);
1246 painter.setPen(pen);
1247 QPen pen(Qt::black, 1);
1248 painter.setPen(pen);
1249 selectedneurons[0] = selectedneurons[1] = -1;
1251 if (networkDialog->enet->drawnxmax > 0 && networkDialog->enet->drawnymax > 0)
1253 networkDialog->cscaley = height() / (float) networkDialog->enet->drawnymax;
1254 networkDialog->cscalex = width() / (float) networkDialog->enet->drawnxmax;
1255 painter.scale(networkDialog->cscalex, networkDialog->cscaley);
1259 painter.scale(1.0,1.0);
1261 painter.setPen(Qt::gray);
1263 p = networkDialog->enet->freep;
1264 for(i=0;i < networkDialog->enet->nneurons;i++)
1266 if (networkDialog->enet->neurongain[i] == 1)
1269 for(i=0;i < networkDialog->enet->nneurons;i++)
1271 if (networkDialog->enet->neuronbias[i] == 1)
1273 networkDialog->biases[i] = *p;
1278 for (i=0; i < networkDialog->enet->net_nblocks; i++)
1280 if (networkDialog->enet->net_block[i][0] == 0)
1281 for (t=networkDialog->enet->net_block[i][1]; t < (networkDialog->enet->net_block[i][1] + networkDialog->enet->net_block[i][2]); t++)
1282 for (b=networkDialog->enet->net_block[i][3]; b < (networkDialog->enet->net_block[i][3] + networkDialog->enet->net_block[i][4]); b++)
1285 if (networkDialog->getcblock() == i)
1290 if (w != networkDialog->enet->DEFAULT_VALUE)
1292 if (w > networkDialog->enet->wrange)
1293 w = networkDialog->enet->wrange;
1294 if (w < (0.0 - networkDialog->enet->wrange))
1295 w = 0.0 - networkDialog->enet->wrange;
1299 cg -= ((w / networkDialog->enet->wrange) * 255);
1300 cb -= ((w / networkDialog->enet->wrange) * 255);
1304 cg += ((w / networkDialog->enet->wrange) * 255);
1305 cr += ((w / networkDialog->enet->wrange) * 255);
1315 painter.setPen(QPen(QColor(cr,cg,cb,255), wid, Qt::SolidLine));
1317 if (abs(networkDialog->enet->neuronxy[b][1] - networkDialog->enet->neuronxy[t][1]) > 20)
1318 painter.drawLine((
float) networkDialog->enet->neuronxy[t][0], (
float) networkDialog->enet->neuronxy[t][1], (
float) networkDialog->enet->neuronxy[b][0], (
float) networkDialog->enet->neuronxy[b][1]);
1321 dx = abs(networkDialog->enet->neuronxy[t][0] - networkDialog->enet->neuronxy[b][0]);
1322 dy = abs(networkDialog->enet->neuronxy[t][1] - networkDialog->enet->neuronxy[b][1]);
1323 if (networkDialog->enet->neuronxy[t][0] < networkDialog->enet->neuronxy[b][0])
1324 sx = networkDialog->enet->neuronxy[t][0];
1326 sx = networkDialog->enet->neuronxy[b][0];
1327 if (networkDialog->enet->neuronxy[t][1] < networkDialog->enet->neuronxy[b][1])
1328 sy = networkDialog->enet->neuronxy[t][1];
1330 sy = networkDialog->enet->neuronxy[b][1];
1331 painter.drawArc((
float) sx,(
float) (sy-20),(
float) dx, (
float) (dy+40), 0 * 16, 180 * 16);
1335 if (networkDialog->enet->net_block[i][0] == 1)
1337 if (networkDialog->getcblock() == i)
1339 selectedneurons[0] = networkDialog->enet->net_block[i][1];
1340 selectedneurons[1] = networkDialog->enet->net_block[i][2];
1342 for(t=networkDialog->enet->net_block[i][1]; t < (networkDialog->enet->net_block[i][1] + networkDialog->enet->net_block[i][2]); t++)
1343 if (networkDialog->enet->neurontype[t] == 1)
1348 for (i=0; i < networkDialog->enet->nneurons; i++)
1350 if (networkDialog->enet->neuronbias[i] == 1)
1352 w = networkDialog->biases[i];
1353 if (w != networkDialog->enet->DEFAULT_VALUE)
1355 if (w > networkDialog->enet->wrange)
1356 w = networkDialog->enet->wrange;
1357 if (w < (0.0 - networkDialog->enet->wrange))
1358 w = 0.0 - networkDialog->enet->wrange;
1362 cg -= ((w / networkDialog->enet->wrange) * 255);
1363 cb -= ((w / networkDialog->enet->wrange) * 255);
1367 cg += ((w / networkDialog->enet->wrange) * 255);
1368 cr += ((w / networkDialog->enet->wrange) * 255);
1378 if (i >= selectedneurons[0] && i < selectedneurons[0]+selectedneurons[1])
1380 painter.setPen(QPen(QColor(cr,cg,cb,255), wid, Qt::SolidLine));
1385 if (i >= selectedneurons[0] && i < selectedneurons[0]+selectedneurons[1])
1387 painter.setPen(QPen(Qt::black, wid, Qt::SolidLine));
1390 if (networkDialog->enet->neurontype[i] == 0)
1391 painter.setBrush(QBrush(QColor(75, 75, 75, 255), Qt::SolidPattern));
1393 if (networkDialog->enet->neurontype[i] == 1)
1394 painter.setBrush(QBrush(QColor(255, 0, 0, 255), Qt::SolidPattern));
1396 if (networkDialog->enet->neurontype[i] == 2)
1397 painter.setBrush(QBrush(QColor(0, 0, 255, 255), Qt::SolidPattern));
1399 painter.setBrush(QBrush(QColor(150, 150, 150, 255), Qt::SolidPattern));
1401 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[i][0] - 5), (
float) (networkDialog->enet->neuronxy[i][1] - 5), 10.0, 10.0);
1404 if (networkDialog->enet->neurongain[i] == 1)
1406 painter.setPen(QPen(QColor(255,255,255,255), wid, Qt::SolidLine));
1407 painter.setBrush(QBrush(QColor(255, 255, 255, 255), Qt::SolidPattern));
1408 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[i][0] - 1), (
float) (networkDialog->enet->neuronxy[i][1] - 1), 2.0, 2.0);
1413 painter.setPen(Qt::black);
1414 for (i=0; i < networkDialog->enet->nneurons; i++)
1416 if (networkDialog->enet->neurondisplay[i] == 1)
1417 painter.setPen(Qt::black);
1419 painter.setPen(Qt::red);
1420 if (i < networkDialog->ninputs)
1421 labelxy.setRect((
float) (networkDialog->enet->neuronxy[i][0] - 5), (
float) (networkDialog->enet->neuronxy[i][1] + 5), 30, 30);
1423 labelxy.setRect((
float) (networkDialog->enet->neuronxy[i][0] - 5), (
float) (networkDialog->enet->neuronxy[i][1] - 18), 30, 30);
1424 painter.drawText(labelxy, networkDialog->neuroncl[i]);
1426 painter.setPen(Qt::darkRed);
1427 if (networkDialog->enet->neuronlesion[i]) painter.drawText(networkDialog->enet->neuronxy[i][0]-5,networkDialog->enet->neuronxy[i][1]-5,
"X");
1430 painter.setBrush(Qt::black);
1431 if (networkDialog->cneuronn == 1)
1432 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[0]][0] - 5), (
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[0]][1] - 5), 10.0, 10.0);
1433 if (networkDialog->cneuronn >= 2)
1435 if (networkDialog->cneuron[0] <= networkDialog->cneuron[1])
1437 for (i=networkDialog->cneuron[0]; i <= networkDialog->cneuron[1]; i++)
1438 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[i][0] - 5), (
float) (networkDialog->enet->neuronxy[i][1] - 5), 10.0, 10.0);
1442 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[0]][0] - 5), (
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[0]][1] - 5), 10.0, 10.0);
1443 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[1]][0] - 5), (
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[1]][1] - 5), 10.0, 10.0);
1446 painter.setBrush(Qt::blue);
1447 if (networkDialog->cneuronn == 3)
1448 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[2]][0] - 5), (
float) (networkDialog->enet->neuronxy[networkDialog->cneuron[2]][1] - 5), 10.0, 10.0);
1449 if (networkDialog->cneuronn == 4 && networkDialog->cneuron[2] <= networkDialog->cneuron[3])
1450 for (i=networkDialog->cneuron[2]; i <= networkDialog->cneuron[3]; i++)
1451 painter.drawEllipse((
float) (networkDialog->enet->neuronxy[i][0] - 5), (
float) (networkDialog->enet->neuronxy[i][1] - 5), 10.0, 10.0);
1462 RendNetwork::mousePressEvent(QMouseEvent *event)
1490 for(i=0; i < networkDialog->enet->nneurons; i++)
1492 if (mdist((
float) x,(
float) y, (
float) networkDialog->enet->neuronxy[i][0] * networkDialog->cscalex, (
float) networkDialog->enet->neuronxy[i][1] * networkDialog->cscaley) < 10.0)
1494 if (networkDialog->cneuronn >= 4)
1495 networkDialog->cneuronn = 0;
1496 networkDialog->cneuron[networkDialog->cneuronn] = i;
1497 networkDialog->cneuronn++;
1499 networkDialog->statusb->setText(QString(
"%1 neurons selected").arg(networkDialog->cneuronn));
1500 emit selectedneuronsChanged();
1507 for (i=0; i < networkDialog->enet->net_nblocks; i++)
1509 if (networkDialog->enet->net_block[i][0] == 0)
1510 for (t=networkDialog->enet->net_block[i][1]; t < (networkDialog->enet->net_block[i][1] + networkDialog->enet->net_block[i][2]); t++)
1511 for (b=networkDialog->enet->net_block[i][3]; b < (networkDialog->enet->net_block[i][3] + networkDialog->enet->net_block[i][4]); b++)
1513 cdist = segmentdist((
float) x, (
float) y, (
float) networkDialog->enet->neuronxy[t][0] * networkDialog->cscalex, (
float) networkDialog->enet->neuronxy[t][1] * networkDialog->cscaley, (
float) networkDialog->enet->neuronxy[b][0] * networkDialog->cscalex, (
float) networkDialog->enet->neuronxy[b][1] * networkDialog->cscaley);
1515 if (cdist < 1 && cdist < dist)
1518 networkDialog->cneuron[0] = t;
1519 networkDialog->cneuron[1] = t;
1520 networkDialog->cneuron[2] = b;
1521 networkDialog->cneuron[3] = b;
1522 networkDialog->cneuronn = 4;
1523 networkDialog->statusb->setText(QString(
"A single connection have been selected"));
1534 networkDialog->cneuronn = 0;
1535 networkDialog->pseudomode = 0;
1536 networkDialog->pseudo_activate_net();
1537 networkDialog->statusb->setText(QString(
"0 selected neurons"));
1538 emit selectedneuronsChanged();
1553 RendNetwork::mouseMoveEvent(QMouseEvent *event)
1569 networkDialog->cneuronn = 0;
1572 for(i=0, cn=-1; i < networkDialog->enet->nneurons; i++)
1573 if (mdist((
float) rnmousex,(
float) rnmousey, (
float) networkDialog->enet->neuronxy[i][0] * networkDialog->cscalex, (
float) networkDialog->enet->neuronxy[i][1] * networkDialog->cscaley) < 10.0)
1577 networkDialog->enet->neuronxy[cn][0] = (float) x / networkDialog->cscalex;
1578 networkDialog->enet->neuronxy[cn][1] = (
float) y / networkDialog->cscaley;
1583 networkDialog->statusb->setText(QString(
"neuron position modified"));
1597 RendNetwork::mouseReleaseEvent(QMouseEvent *event)
1608 if (networkDialog->grid > 0)
1611 rnmousex=
event->x();
1612 rnmousey=
event->y();
1618 for(i=0, cn=-1; i < networkDialog->enet->nneurons; i++)
1619 if (mdist((
float) rnmousex,(
float) rnmousey, networkDialog->enet->neuronxy[i][0], networkDialog->enet->neuronxy[i][1]) < 10.0)
1623 oldp1 = networkDialog->enet->neuronxy[cn][0];
1624 oldp2 = networkDialog->enet->neuronxy[cn][1];
1625 networkDialog->enet->neuronxy[cn][0] = (float) (((
int) networkDialog->enet->neuronxy[cn][0]) / networkDialog->grid * networkDialog->grid);
1626 networkDialog->enet->neuronxy[cn][1] = (float) (((
int) networkDialog->enet->neuronxy[cn][1]) / networkDialog->grid * networkDialog->grid);
1627 if ((oldp1 - networkDialog->enet->neuronxy[cn][0]) > (networkDialog->grid / 2))
1628 networkDialog->enet->neuronxy[cn][0] += networkDialog->grid;
1629 if ((oldp2 - networkDialog->enet->neuronxy[cn][1]) > (networkDialog->grid / 2))
1630 networkDialog->enet->neuronxy[cn][1] += networkDialog->grid;
1632 networkDialog->statusb->setText(QString(
"neuron's position modified"));
1642 *o = (float) (((
int) *o) / networkDialog->grid * networkDialog->grid);
1643 *(o + 1) = (
float) (((int) *(o + 1)) / networkDialog->grid * networkDialog->grid);
1644 if ((oldp1 - *o) > (networkDialog->grid / 2))
1645 *o += networkDialog->grid;
1646 if ((oldp2 - *(o + 1)) > (networkDialog->grid / 2))
1647 *(o + 1) += networkDialog->grid;
1648 networkDialog->statusb->setText(QString(
"neuron's position modified"));
1663 RendNetwork::mouseDoubleClickEvent(QMouseEvent* )
1671 RendNetwork::mdist(
float x,
float y,
float x1,
float y1)
1676 qdist = ((x-x1)*(x-x1)) + ((y-y1)*(y-y1));
1677 return(sqrt(qdist));
1687 RendNetwork::segmentdist(
float px,
float py,
float ax,
float ay,
float bx,
float by)
1691 dab = sqrt(((ax-bx)*(ax-bx)) + ((ay-by)*(ay-by)));
1692 dpa = sqrt(((px-ax)*(px-ax)) + ((py-ay)*(py-ay)));
1693 dpb = sqrt(((px-bx)*(px-bx)) + ((py-by)*(py-by)));
1695 if (dpa < dab && dpb < dab)
1696 return((dpa+dpb)-dab);
1702 EvoSlider::EvoSlider(
float *ref,
float rangemin ,
float rangemax, QWidget * parent)
1703 : QDoubleSpinBox(parent) {
1705 setRange(rangemin, rangemax);
1706 setSingleStep(0.05);
1708 connect(
this,SIGNAL(valueChanged(
double)),
this, SLOT(updateValue(
double)));
1711 void EvoSlider::updateValue(
double ival)
1714 emit networkChanged();
1718 MixerDialog::MixerDialog(Evonet *enet, NetworkDialog* netd)
1723 layout=
new QGridLayout(
this);
1726 void MixerDialog::setUpMixer()
1731 foreach(QObject* child, children()) {
1732 delete dynamic_cast<QWidget*
>(child);
1737 statusmixer =
new QLabel(
"",
this);
1738 if (netdl->pseudomode == 2)
1739 statusmixer->setText(QString(
"weights:"));
1740 if (netdl->pseudomode == 1)
1741 statusmixer->setText(QString(
"t-const:"));
1742 if (netdl->pseudomode == 3)
1743 statusmixer->setText(QString(
"biases:"));
1744 if (netdl->pseudomode == 4)
1745 statusmixer->setText(QString(
"gains:"));
1747 statusmixer->setText(QString(
"neurons:"));
1748 layout->addWidget(statusmixer,0,0);
1763 if (netdl->pseudomode == 2)
1766 lt = netdl->cneuron[0];
1767 li = netdl->cneuron[2];
1769 for(
int i=0;i<evonet->
nselected;i++,v++,li++)
1771 if (li > netdl->cneuron[3])
1774 li = netdl->cneuron[2];
1777 layout->addWidget(
new QLabel(evonet->neuronl[lt],
this),1,i);
1778 EvoSlider* slide =
new EvoSlider(v,(0 - evonet->
getWrange()),evonet->
getWrange(),
this);
1779 connect( slide, SIGNAL(networkChanged()), netdl->rendNetwork, SLOT(update()) );
1780 layout->addWidget(slide,2,i);
1781 layout->addWidget(
new QLabel(evonet->neuronl[li],
this),3,i);
1787 l = netdl->cneuron[0];
1788 for(
int i=0;i<evonet->
nselected;i++,v++,l++)
1790 layout->addWidget(
new QLabel(evonet->neuronl[l],
this),1,i);
1791 EvoSlider* slide =
new EvoSlider(v,(0 - evonet->
getWrange()),evonet->
getWrange(),
this);
1792 connect( slide, SIGNAL(networkChanged()), netdl->rendNetwork, SLOT(update()) );
1793 layout->addWidget(slide,2,i);
1803 layout->addWidget(
new QLabel(evonet->neuronl[i],
this),1,i);
1805 connect( slide, SIGNAL(networkChanged()), netdl->rendNetwork, SLOT(update()) );
1806 layout->addWidget(slide,2,i);
1812 void MixerDialog::setNet(Evonet* n)
1820 #if defined(_MSC_VER)
1821 #pragma warning(pop)
float getWrange()
return the value of wrange (which also determine the range in which all parameters are normalized) ...
int nselected
Number of parameters selected through the graphic interface Enable the user to modify the parameters ...
int getNoNeurons()
return the total number of neurons
int load_net_blocks(const char *filename, int mode)
Load the description of the neural architecture from .net of .phe file (see the create_net_block meth...
bool neuronlesion[MAXN]
a vector that speficy lesioned and unlesioned neurons
static void info(QString msg)
int neuronlesions
Whether one or more neurons have been lesioned.
int neurondisplay[MAXN]
the vectors that specify for each neuron whether it should be displayed or not by the neuron monitor ...
float neuronlesionVal[MAXN]
the value to be assigned to the state of lesioned neurons
void save_net_blocks(const char *filename, int mode)
Save the description of the neural architecture into a .net of .phe file (see the create_net_block me...
float ** selectedp
pointer to the list pointer-to-parameters selected through the graphic interface Enable the user to m...
double neuronrange[MAXN][2]
the matrix that contain the variation range of neurons used by the neuron monitor graphic widget ...