From 3df2f1b3c9c908206c4f053e7bdcc617e8ea052e Mon Sep 17 00:00:00 2001 From: lrcstdio <316294622@qq.com> Date: Mon, 14 May 2018 21:21:52 +0800 Subject: [PATCH 1/3] 2.0 --- crossover.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ decode.cpp | 29 ++++++++++++++++++++ evolution.h | 41 +++++++++++++++++++++++++++ init.cpp | 32 ++++++++++++++++++++++ input.cpp | 37 +++++++++++++++++++++++++ lsort.cpp | 18 ++++++++++++ main.cpp | 13 +++++++++ mutate.cpp | 11 ++++++++ output.cpp | 23 ++++++++++++++++ test.cpp | 19 +++++++++---- 10 files changed, 294 insertions(+), 5 deletions(-) create mode 100644 crossover.cpp create mode 100644 decode.cpp create mode 100644 evolution.h create mode 100644 init.cpp create mode 100644 input.cpp create mode 100644 lsort.cpp create mode 100644 main.cpp create mode 100644 mutate.cpp create mode 100644 output.cpp diff --git a/crossover.cpp b/crossover.cpp new file mode 100644 index 0000000..1a143a9 --- /dev/null +++ b/crossover.cpp @@ -0,0 +1,76 @@ +#include "evolution.h" +#include +#include +#include +#include +void jobshop::select(double* _q) +{ + _q[0] = r1*exp(r2*decode(genes[0])); + for(int i=1;ip1) n1=i; + if(n2==-1 && q[i]>p2) n2=i; + if(n1!=-1 && n2!=-1) break; + } + + do + { + m1=rand()%len; + m2=rand()%len; + }while(m1==m2); + if(m1>m2) {int t;t=m1;m1=m2;m2=t;} + + memset(book1,false,sizeof(book1)); + memset(book2,false,sizeof(book2)); + + for(int i=m1;i<=m2;i++) + { + genes[cnt][i]=tgenes[n1][i]; + for(int j=0;j + +inline int max(int a, int b){if(a>=b) return a;return b;} + +int jobshop::decode(int *g) +{ + int d[15],p[15]; + memset(TT,0,sizeof(TT)); + memset(d,0,sizeof(d)); //对应机器上的最大完成时间 + memset(p,0,sizeof(p)); //对应工件上的最大完成时间 + + for(int j=0;j +#include +#include +void jobshop::init() +{ + int *fa; + fa=(int *)malloc(len*sizeof(int)); + for (int i = 0; i < len; ++i) { + fa[i]=i+1; + } + for(int k=0;k +#include +#include "evolution.h" + +jobshop::jobshop(int nn,int mm) +{ + n=nn; + m=mm; + len=ans=0; + memset(TMJ,0,sizeof(TMJ)); + memset(genes,0,sizeof(genes)); + memset(pc,0,sizeof(process)); +} + +void jobshop::input() +{ + int j,k,a,b,cnt=0; //k��ʾ�����ţ�a��ʾʱ�䣬b��ʾ������ + while(scanf("%d",&k)&&k!=-1) + { + j=0; + startpro[k]=cnt+1; + while(scanf(" (%d,%d)",&a,&b)) + { + pc[++len].t=a; + pc[len].m=b; + pc[len].i=k; + pc[len].j=++j; + TMJ[b][len]=a; + ++cnt; + } + } + +} diff --git a/lsort.cpp b/lsort.cpp new file mode 100644 index 0000000..f7edc85 --- /dev/null +++ b/lsort.cpp @@ -0,0 +1,18 @@ +// +// Created by liuren on 18-5-14. +// +#include +#include +#include "evolution.h" +#include +void jobshop::lsort(int *a) +{ + int *b; + b=(int *)malloc((n+1)*sizeof(int)); + memset(b,0,sizeof(b)); + for(int i=0;i +#include "evolution.h" +using namespace std; + +int main() +{ + int n,m; + cin>>n>>m; + jobshop js(n,m); + js.input(); + js.test(); + return 0; +} \ No newline at end of file diff --git a/mutate.cpp b/mutate.cpp new file mode 100644 index 0000000..2f44078 --- /dev/null +++ b/mutate.cpp @@ -0,0 +1,11 @@ +// +// Created by liuren on 18-5-14. +// + +#include "evolution.h" +#include +#include + +void jobshop::mutate() { + +} \ No newline at end of file diff --git a/output.cpp b/output.cpp new file mode 100644 index 0000000..ed2eb6f --- /dev/null +++ b/output.cpp @@ -0,0 +1,23 @@ +// +// Created by liuren on 18-5-14. +// + +#include "evolution.h" +#include + +void jobshop::output() +{ + decode(theBestGene); + for(int i=0;i -int main(int argc, char const *argv[]) { - char g[15][15*15]; - printf("..\n" ); - return 0; +// +// Created by liuren on 18-5-14. +// + +#include "evolution.h" +#include + +void jobshop::test() +{ + int temp[9]; + for(int i=0;i<9;i++) + temp[i]=i+1; + memcpy(theBestGene,temp,9*sizeof(int)); + output(); } From af6caf209a58e33b08b195104452d58c19cb7bcf Mon Sep 17 00:00:00 2001 From: Zachary <34575677+hhuangzhen@users.noreply.github.com> Date: Mon, 14 May 2018 21:26:29 +0800 Subject: [PATCH 2/3] Delete Record Maintenance.c --- Record Maintenance.c | 197 ------------------------------------------- 1 file changed, 197 deletions(-) delete mode 100644 Record Maintenance.c diff --git a/Record Maintenance.c b/Record Maintenance.c deleted file mode 100644 index b37b64b..0000000 --- a/Record Maintenance.c +++ /dev/null @@ -1,197 +0,0 @@ -#include -#include -#include - -typedef struct{ - int id; - char name[40]; - int num; - double price; -}cd; - -void init(FILE *f) -{ - cd a[100]; - memset(a,0,sizeof(a)); - rewind(f); - fwrite(a,sizeof(cd),100,f); - printf("100ռ¼\n\n"); -} - -void input(FILE *f) -{ - cd a[100]; - int id[100]; - int cnt=-1; - memset(a,0,sizeof(a)); - rewind(f); - fread(a,sizeof(cd),100,f); - while(1) - { - printf("ƷϢ[IDΪ-1]\n"); - printf("ƷID:"); - int t; - scanf("%d", &t); - getchar(); - if(t==-1) break; - a[t].id=t; - printf("Ʒ:"); - gets(a[t].name); - printf(":"); - scanf("%d", &a[t].num); - printf("۸:"); - scanf("%lf", &a[t].price); - - id[++cnt]=t; - } - rewind(f); - fwrite(a,sizeof(cd),100,f); - - printf("ƷϢ\nƷϢ\n"); - printf("¼ţƷID\tƷ\t\t\t۸\n"); - - for(int i=0;i<=cnt;i++) - printf("%-17d\t%-16s%-5d\t%.2lf\n", id[i], a[id[i]].name, a[id[i]].num, a[id[i]].price); - putchar('\n'); -} - -double read() -{ - char ch; - double t=0; - double r=1; - int flag=0; - while((ch=getchar())!='\n') - { - flag=1; - if(isdigit(ch)) - { - if(r==1) t=t*10+(ch-'0'); - else - { - t+=(ch-'0')*r; - r*=0.1; - } - } - else if(ch=='.') r=0.1; - } - if(flag) return t; - return -1; -} - -void updata(FILE *f) -{ - cd a[100]; - rewind(f); - fread(a,sizeof(cd),100,f); - - while(1) - { - printf("ƷID[IDΪ-1]:\n"); - int t; - scanf("%d", &t); - getchar(); - if(t==-1) break; - if(strlen(a[t].name)==0) printf("Բ𣬼¼Ϊ%dƷڣ޷\n", t); - else - { - printf("ԭƷϢ\n"); - printf("¼ţƷID\tƷ\t\t\t۸\n"); - printf("%-17d\t%-16s%-5d\t%.2lf\n", a[t].id, a[t].name, a[t].num, a[t].price); - printf("Ϣ[ijֱӰس]:\n"); - printf("Ʒ:"); - int j=0; - int flag=0; - double temp; - char ch; - while((ch=getchar())!='\n') flag=1,a[t].name[j++]=ch; - if(flag==1) a[t].name[j]='\0'; - printf(":"); - if((temp=read())!=-1) a[t].num=(int)temp; - printf("۸:"); - if((temp=read())!=-1) a[t].price=temp; - rewind(f); - fseek(f,t*sizeof(cd),0); - fwrite(&a[t],sizeof(cd),1,f); - printf("ºƷϢ:\n"); - printf("¼ţƷID\tƷ\t\t\t۸\n"); - printf("%-17d\t%-16s%-5d\t%.2lf\n", a[t].id, a[t].name, a[t].num, a[t].price); - } - } - printf("¹\n\n"); -} - -void output(FILE *f) -{ - cd a[100]; - rewind(f); - fread(a,sizeof(cd),100,f); - printf("ƷϢ:\n"); - printf("¼ţƷID\tƷ\t\t\t۸\n"); - for(int i=0;i<100;i++) - { - if(strlen(a[i].name)!=0) - printf("%-17d\t%-16s%-5d\t%.2lf\n", a[i].id, a[i].name, a[i].num, a[i].price); - } - putchar('\n'); -} - -void _delete(FILE *f) -{ - cd a[100]; - rewind(f); - fread(a,sizeof(cd),100,f); - while(1) - { - printf("ɾƷID[¼Ϊ-1ɾ]:\n"); - int t; - scanf("%d", &t); - getchar(); - if(t==-1) break; - if(strlen(a[t].name)==0) printf("Բ𣬼¼Ϊ%dƷڣ޷ɾ\n", t); - else - { - printf("ƷϢ:\n"); - printf("¼ţƷID\tƷ\t\t\t۸\n"); - printf("%-17d\t%-16s%-5d\t%.2lf\n", a[t].id, a[t].name, a[t].num, a[t].price); - printf("Ƿȷʵɾ(ȷϰYȡN)\n"); - if(getchar()=='N') printf("ѡɾ¼Ϊ%dƷ\n", t); - else - { - memset(a[t].name,0,sizeof(a[t].name)); - a[t].num=0; - a[t].price=0; - rewind(f); - fseek(f,t*sizeof(cd),0); - fwrite(&a[t],sizeof(cd),1,f); - printf("¼Ϊ%dƷɹɾ\n", t); - output(f); - } - } - } - printf("ɾ\n\n"); -} - -int main(int argc, char const *argv[]) { - FILE *f = fopen("commodity.dat","rb+"); - while(1) - { - printf("ѡ\n"); - printf("1--һ100ռ¼ļ\n2--ƷϢ\n3--Ʒ¼\n4--ɾƷ¼\n5--ȫƷ¼\n6--˳\n"); - printf("[ѡ]"); - int q; - scanf("%d", &q); - if(q==1) init(f); - if(q==2) input(f); - if(q==3) updata(f); - if(q==4) _delete(f); - if(q==5) output(f); - if(q==6) - { - printf("нټ\n\n"); - break; - } - } - fclose(f); - return 0; -} From ce4d57abcebb58080dcf2adf3e3886804fa13fed Mon Sep 17 00:00:00 2001 From: Zachary <34575677+hhuangzhen@users.noreply.github.com> Date: Mon, 14 May 2018 21:26:41 +0800 Subject: [PATCH 3/3] Delete commodity.dat --- commodity.dat | Bin 5600 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 commodity.dat diff --git a/commodity.dat b/commodity.dat deleted file mode 100644 index 90d48123bedd99e50badf7d4aea953a343265350..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5600 zcmZQz7zNlufE6g1lbBn8O%7d594PQjBc}h*S9u3?Ia>2MXl((S`CLGLMq+MmY7v?Q z7A{CF1ZX(GSfli42#kinXb6mkz-S1JhQMeDjE2By2#kinXb6mkz-S1JhQMeDjE2By L2#kgR^+EsugM|p>