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("请输入更新信息[如某项不更新请直接按回车键]:\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; -} diff --git a/commodity.dat b/commodity.dat deleted file mode 100644 index 90d4812..0000000 Binary files a/commodity.dat and /dev/null differ 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锟斤拷示锟斤拷锟斤拷锟脚o拷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(); }