Category Archives: #Automation

Source Code for my UVI senior research project – Back in 2000 !!

Here is the source code for my senior research project on Genetic Algorithms from back in 2000. Amazing !!

 

/*
Copyright 2000 Stanford Mings

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include
*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

struct generation
{
int string[5][10];
int fitness[5];
};

void showgeneration(struct generation gp);
void updatefitness(struct generation *gp);
void makepopulation(struct generation *gp);
void reproduce(struct generation *gp);
void savebest(struct generation *gp, int best[10]);
void replacebest(struct generation *gp, int best[10]);

void mutategeneration(struct generation *gp)
{
int or,rm,m,v=2,p=0,mod=0;
/*
for(m=0;m<5;m++)
{
for(v=0;v<10;v++)
{
rm=rand()%55;
// rm=1;
if ((rm==p)&&(mod<10))
{
(*gp).string[m][v]=(rm)%3;
printf(“Mutation at string #%d”,m);
printf(” and element #%d”,v);
printf(” with it being changed to %d”,rm%3);
printf(” !!\n”);
mod++;
}
p++;
}
}
*/
// srand(time(NULL));
for (p=0;p<v;p++)
{
rm=rand()%50;
mod=rand()%3;
or=(*gp).string[rm/10][rm%10];
(*gp).string[rm/10][rm%10]=mod;
// printf(“\n Printing sting %d at point %d from %d to %d”,rm/11,rm%11,or,mod);
}
// printf(“\n”);

}

void reproduce(struct generation *gp)
{
int m,v,f,g,k;
int val[5];
struct generation newgp;
val[0]=(*gp).fitness[0];
k=(*gp).fitness[0];

for(m=1;m<5;m++)
{
k+=(*gp).fitness[m];
val[m]=(*gp).fitness[m]+val[m-1];
}

for (m=0;m<5;m++)
{
g=rand()%k;
f=0;
while(val[f]<g)
f++;
for(v=0;v<10;v++)
newgp.string[m][v]=(*gp).string[f][v];
}

(*gp)=newgp;
}

void savebest(struct generation *gp,int best[10])
{
int bst,v,m,k;
bst=(*gp).fitness[0];
v=0;
for(m=1;m<5;m++)
if (bst<(*gp).fitness[m])
{
v=m;
bst=(*gp).fitness[m];
}
for (k=0;k<10;k++)
best[k]=(*gp).string[v][k];
}

void replacebest(struct generation *gp,int best[10])
{
int v,m,k,d;
v=rand()%5;
// printf(“\n Replacing %d \n”,v);
for (k=0;k<10;k++)
(*gp).string[v][k]=best[k];
}

void makepopulation(struct generation *gp)
{

int d,v,j,sum=0,m,s,p=0,rpick[5],st[5],fn[5];
struct generation gtemp=(*gp);
int newpop[5];

for(m=0;m<5;m++)
sum=sum+(*gp).fitness[m];
d=0;
j=0;
while (d<5)
{
st[d]=j;
fn[d]=j+(*gp).fitness[d];
j=(*gp).fitness[d]+j;
d++;
}

for(m=0;m<5;m++)
rpick[m]=rand()%sum;

for (m=0;m<5;m++)
for(p=0;p<5;p++)
if((rpick[m]>=st[p])&&(rpick[m]<fn[p]))
newpop[m]=p;

for (p=0;p<5;p++)
for(v=0;v<10;v++)
(*gp).string[p][v]=gtemp.string[newpop[p]][v];

/*
for(p=0;p<5;p++)
{
printf(“\n String #%d”,p);
printf(” New String #%d”,newpop[p]);

}
printf(“\n”);
scanf(“%d”,&p);
*/
updatefitness(gp);
}

void xovergeneration(struct generation *gp)
{
int stg1,stg2,xpoint,xlen,m,xver[10];
stg1=rand()%5;
stg2=rand()%5;
while (stg2==stg1)
stg2=rand()%5;
xpoint=rand()%8;
// printf(“\n Xpoint =%d and Xlen= %d”,xpoint, xlen);
xlen=1+(rand()%8);
// printf(“\n Xpoint =%d and Xlen= %d”,xpoint, xlen);
while((xlen+xpoint)>=10)
xlen=1+rand()%8;
// printf(“\n Xpoint =%d and Xlen= %d”,xpoint, xlen);
// xpoint=2;
m=xpoint;
while(m<(xpoint+xlen))
{
xver[m]=(*gp).string[stg1][m];
m++;
}

m=xpoint;

// showgeneration(*gp);
while(m<(xlen+xpoint))
{
(*gp).string[stg1][m]=(*gp).string[stg2][m];
(*gp).string[stg2][m]=xver[m];
m++;
}

/* printf(“\n The xchange points are from element #%d”,xpoint);
printf(” to #%d”,xlen+xpoint);
printf(” for strings %d”,stg1);
printf(” and %d”,stg2);
printf(“\n\n”); */
// scanf(“%d”,stg2);

// updatefitness(gp);
// showgeneration(*gp);
}

void reproducegeneration(struct generation *gp)
{
int xpoint,m,v,hfit1,hfit2,lfit,lstring,stg1,stg2,xver[10];
hfit1=0;
hfit2=0;
lfit=22;
lstring=0;
for (m=0;m<5;m++)
{
if (hfit1<(*gp).fitness[m])
{
hfit1=(*gp).fitness[m];
stg1=m;
}
// srand(stg1);
}

stg1=rand()%5;
while(stg2==stg1)
stg2=rand()%5;

for(m=0;m<5;m++)
if (lfit>(*gp).fitness[m])
{
lfit=(*gp).fitness[m];
lstring=m;
}

/* This code here needs to be updated so that it will set the fitness to the
strings of the highest values(2) including those strings that have the
same value
*/
/* for(m=0;m<5;m++)
{
if ((hfit2<(*gp).fitness[m])&&((*gp).fitness[m]!=hfit1))
{
hfit2=(*gp).fitness[m];
stg2=m;
}
}
*/

// xpoint=rand()%10;
xpoint=5;
// printf(“\nS1 =%d”,lstring);
// printf(“\nL =%d”,lfit);
// printf(“\nXpoint=%d”,xpoint);

// printf(“Bad string = %d”,lstring);
// printf(“\n first string = %d”,stg1);
// printf(“\n second string = %d”,stg2);
//

// showgeneration((*gp));
m=0;
while(m<10)
{
if (m>xpoint)
(*gp).string[lstring][m]=(*gp).string[stg2][m];
else
(*gp).string[lstring][m]=(*gp).string[stg1][m];
m++;
}

updatefitness(gp);

// printf(“Bad string = %d”,lstring);
// printf(“\n first string = %d”,stg1);
// printf(“\n second string = %d”,stg2);
// showgeneration((*gp));

}

void showgeneration(struct generation gen)
{
int m,v;
for(m=0;m<5;m++)
// printf(“\n—————-\n”);
{
for(v=0;v<10;v++)
{
printf(“%d”,gen.string[m][v]);
printf(” “);
}
printf(“|=%d”,gen.fitness[m]);
printf(“\n”);
}
printf(“\n”);
// scanf(“%d”,&v);
}

void findgoal(struct generation gen,int s)
{
int p,m;
for(m=0;m<5;m++)
if (gen.fitness[m]>=20)
{
printf(“\n\nFINISH !!!!\n Generation =%d”,s);
printf(“\n”);
showgeneration(gen);
scanf(“%d”,&p);
}
}

void updatefitness(struct generation *gp)
{

int f,m,v;
for (m=0;m<5;m++)
{
f=0;
for (v=0;v<10;v++)
f=f+(*gp).string[m][v];
(*gp).fitness[m]=f;
}
}

struct generation populate()
{
int m,v;
struct generation popg;
for (m=0;m<5;m++)
for (v=0;v<10;v++)
// popg.string[m][v]=rand();
popg.string[m][v]=rand()%3;
return popg;
}

void main()
{
struct generation gen[5000000],geno;
int s,m,rm,in,g;
int best[10];
struct tm tim;
time_t timet;
unsigned seed;
timet=time(NULL);
// printf(“Please enter seed :%d”,timet);
// scanf(“%u”,&seed);
// seed=904;
seed=timet;
srand(seed);
gen[0]=populate();
updatefitness(&gen[0]);
// printf(“Please enter mutation factor : %d”,tim.tm_min);
// scanf(“%d”,&rm);
// rm=10;
printf(“\nEnter the # of generations (1-5000000) :”);
scanf(“%d”,&g);
// g=5000000;
printf(“\nShow generations ?(1 for yes, 0 for no) :”);
scanf(“%d”,&s);
// s=0;
printf(“\n\n Searching…….\n”);
for(m=0;m<g;m++)
{
// printf(“Generation %d”,m);
// printf(“\n”);
// showgeneration(gen[m]);
// seed=time(NULL);
// srand(seed);
// showgeneration(gen[m]);
savebest(&gen[m],best);
reproduce(&gen[m]);
updatefitness(&gen[m]);
// showgeneration(gen[m]);
// makepopulation(&gen[m]);
// updatefitness(&gen[m]);
mutategeneration(&gen[m]);
updatefitness(&gen[m]);
xovergeneration(&gen[m]);
updatefitness(&gen[m]);
replacebest(&gen[m],best);
updatefitness(&gen[m]);
// reproducegeneration(&gen[m]);
// updatefitness(&gen[m]);
if (s==1)
showgeneration(gen[m]);
// printf(“\n”);
// reproducegeneration(&gen[m]);
// makepopulation(&gen[m]);
findgoal(gen[m],m);
// printf(“\n”);
// scanf(“%d”,&in);
// printf(“\n”);
if ((m+1)!=g)
gen[m+1]=gen[m];
}
}

FreeBSD 11.1 on the desktop

So I made the jump to using FreeBSD on the desktop and it’s beginning to grow on me. Some notes.

  • I got the Nextcloud client running after running into a bunch of issues with Qt5. This now allows me to keep my files in sync and makes the time on my BSD box that much more productive.  Workflow is now enhanced.
  • Using XFCE as my desktop with Compiz as a windows manager. I fell in in love with the cube multidesktop feature when I saw it at a Linuxworld years ago.
  • Now that I am doing things mostly from the terminal, it gives me the incentive and environment to automate more and more.
  • Have to look into some other browsers beyond Chromium and Firefox.
  • Once I have rdesktop and xfreerdp, I can manage my MS Windows systems without much issues.
  • My previous setup was a Win7 system with 3 monitors.  While I could use the same 3 monitors, I realized having 12 (3*4) desktops may have been a bit too much.  So now I have two monitors and thus 8 desktops.  A major jump in productivity

All in all, a challenging experience, but one that I am glad I did.

The TODO list

  • ZFS file system
  • Custom launcher(s)
  • Custom dashboard

 

Great book that I am reading: “Bullshit Jobs: A Theory”

This book by David Graeber should be read by technologist and anyone who is interested in systems and processes.


I build for me….

I build tools for my use.  Hardware, Software, and services.  I build not to sell, rent and/or give to others.  One cannot solve the problems of others, until she can solve her own.

While I am supporter of Free Software, both beer and freedom, I most importantly support the freedom to do what you want.  This is because I don’t want anyone telling me what to do with my life.

If I follow your instructions, know that it is because I deem it in my own best interest.  Our goals have been aligned.  Nothing more, nothing less.

ZFS Testing

Spent the day testing ZFS, via FreeNAS, as a VM storage medium.  Got it to do snapshots, rollbacks, clones and the most important, incremental backup to remote systems.

The goal is for this to allow my core data to be replicated to remote repos for security issues.  This is most imperative after Irmaria.

Resources that were most helpful.

https://www.headdesk.me/ZFS_incremental_replication

http://portrix-systems.de/blog/brost/zfs-migration-using-incremental-sendreceive/

Automata

Automata theory is the study of abstract machines and automata, as well as the computational problems that can be solved using them. It is a theory in theoretical computer science and discrete mathematics (a subject of study in both mathematics and computer science). The word automata (the plural of automaton) comes from the Greek word αὐτόματα, which means “self-acting”.

wikipedia

Veranda to dish….

On June 20th, I took the step to self reliance and purchased an vertical aeroponics system from Al Henry [alhenry2@gmail.com] a local(USVI) hydroponics system maker and this weekend harvested the first of many produce.

Here is the system

Before

Currently:

Plants are :

Kale
Parsley
Thyme & Oregano
Basil
Spinach
Collard Greens
Lettuce
Arugula
Onions (Scallions)
Chives
Rosemary
Sweet Marjoram
Cilantro
Swiss Chard
Mustard (Greens)
Lemon Grass
Mint
Sage
Tarragon

 

This is a time lapse of the system(click on image to start animation):

And the resulting meal that used produce from the system.

Stanford’s random thoughts….

The moment that humans can be recreated by either robots, biological clones and/or combination, entertainment stars will not die. In fact they will have found the “fountain of youth”

Their estates will keep them around and you can invest in them since they will be will be traded on the wall street.