|
|
February 28 About ME -----Preious Yet another stupid undergraduate. The sun should never set upon an argument.
Interests <Possibly, searching for the goal of life while living peacefully; learn while playing $_$> -----Previous <PLEASE FILL THE FORM AUTOMATICALLY, THANKS> <Programming. English. Computer. Games. Technology Issues.> 考虑一下以后学些什么好(或许不是以后吧,比如,就最近,然后会一直坚持的那种)
做了一些签
抽到了
嵌入式, embed linux + any related
数据库和web, SOAP, MySQL或Oracle深入
还是软件啊
于是打算从option 1开始着手了
linux, gcc, qt, drivers(vxworks)
多少有点开心
至少往前慢慢爬了这么一小步 January 09 俺又回来了. 想出一个好方法, 能保持一段时间的更新.. 就是把每天吃过的东西都记在Space上.. .. . . 说真的, 冷%%%% 下次上线的时候要更新个人信息! 不能一直当'无业游民~' BTW, an interesting website: http://www.network-science.de/ascii/ // ) ) // ) ) // / / (( ( ) __ ( ) ___ (( ___ ___ //___ / / ___ // // ___ \\ / / // ) ) / / // / / (( ) ) \\ // ) ) // / / (( ) ) / ___ / //___) ) // // // ) ) ) ) / / // / / // / / \ \ ) ) // / / ((___/ / \ \ // / / // // // // / / ((___ / / / / // / / ((___( ( // ) ) ((___ / / ((___( ( / / // ) ) // / / ((____ // // ((___/ /
法国回来的小李子(别打我)明天见面了. 突然想起来上Space瞅瞅. 时间过得好快.. 给大家发了些Friend Link Request (主要是找人方便些 ^_^) 回家的时候跟老爸说, 其实上班也挺无聊的 -- 每天就是上班和回家, 基本的业余时间是用来看下的电影, 柯南和海贼, 玩游戏, 还有很偶尔的看书. 一直是没常性的人啊, 总也不能有个持久的爱好 -- 其实这么说来, 坚持上班简直是非常的难了 -- 昏 倒
每天都用忙碌的藉口麻痹自己, 然后去放肆的玩点啥, 或者歇着~ 似乎是觉得只要认真工作就能得到应该得到的东西, 可事实真的会这么简单么?
&@#$&**@#$!...
继续寻找答案中, 不过我猜也许不会这么简单吧. 还是加快速度, 多做些值得回忆的东西才好, 工作上的项目也好, 学习/复习的知识也好, 总比晃着脑袋慢慢挣钱要来的满足.
因为我已经, 23周了(24啦!) 没法过了...
Dear Friends,
(In case anyone had seen this update =_=#) Please leave me a message here or MSN, so I can add you to my contact list on my company mailbox. :)
Best wishes, Sirius 不搞了... 想想IPR的东西了, 已经拖了3天啦...
June 01 基本上, 没什么了不得的. 随便写写了
网上能找到的那个程序 貌似不是很好. 所以写了这个.
因为没去找'怎样的矩阵是无解或只有错误解的矩阵', 所以没有输入的正确性判断.
#include <stdio.h> #define MAX_SIZE 50 typedef struct matrix { int cost[MAX_SIZE][MAX_SIZE]; int ori_cost[MAX_SIZE][MAX_SIZE]; int height; int zeros; int row_zeros[MAX_SIZE]; int col_zeros[MAX_SIZE]; int row_lined[MAX_SIZE]; int col_lined[MAX_SIZE]; int result_idx; int result[MAX_SIZE][2]; } matrix; int temp[MAX_SIZE][MAX_SIZE] = {0};matrix matrix_input(); void calc_zeros(matrix &mt); void select_zeros(matrix &mt); void output_result(matrix &mt); void re_calculation(matrix &mt); void dual_optimal(matrix &mt); void debug_mt(matrix &mt) { int i = 0, j = 0; printf("\nMatrix Data:\n"); for (i = 0; i < mt.height; i ++) { for (j = 0; j < mt.height; j ++) printf("%4d", mt.cost[i][j]); printf("\n"); } }void select_zeros(matrix &mt) { int i = 0, j = 0; int min_zeros = mt.height, min_zeros_idx = mt.height, last_min_zeros = 0; int last_matrix_zeros = mt.zeros + 1; mt.result_idx = 0; while (last_matrix_zeros > mt.zeros) { last_matrix_zeros = mt.zeros; min_zeros = mt.height; min_zeros_idx = mt.height; for (i = 0; i < mt.height; i ++) { if (mt.row_lined[i] == 0 && mt.row_zeros[i] < min_zeros && mt.row_zeros[i] != 0) { min_zeros = mt.row_zeros[i]; min_zeros_idx = i; } } last_min_zeros = min_zeros; for (j = 0; j < mt.height; j ++) { if (mt.col_lined[j] == 0 && mt.col_zeros[j] < min_zeros && mt.col_zeros[j] != 0) { min_zeros = mt.col_zeros[j]; min_zeros_idx = j; } } if (min_zeros != mt.height) { if (last_min_zeros == min_zeros) { for (j = 0; j < mt.height; j ++) { if (mt.col_lined[j] == 0 && mt.cost[min_zeros_idx][j] == 0) break; } if (j < mt.height) { mt.col_lined[j] = 1; mt.result[mt.result_idx][0] = min_zeros_idx; mt.result[mt.result_idx][1] = j; mt.col_zeros[j] --; mt.row_zeros[min_zeros_idx] --; mt.zeros --; mt.result_idx ++; } } else { for (i = 0; i < mt.height; i ++) { if (mt.row_lined[i] == 0 && mt.cost[i][min_zeros_idx] == 0) break; } if (i < mt.height) { mt.row_lined[i] = 1; mt.result[mt.result_idx][0] = i; mt.result[mt.result_idx][1] = min_zeros_idx; mt.col_zeros[min_zeros_idx] --; mt.row_zeros[i] --; mt.zeros --; mt.result_idx ++; } } } } if (mt.result_idx == mt.height) { //If any echos output_result(mt); } else { //If any echos re_calculation(mt); } }void re_calculation(matrix &mt) { int i = 0, j = 0, min_d = 65535; for (i = 0; i < mt.height; i ++) { if (mt.row_lined[i] != 0) continue; for (j = 0; j < mt.height; j ++) { if (mt.col_lined[j] != 0) continue; temp[i][j] = mt.cost[i][j]; if (temp[i][j] > min_d) min_d = temp[i][j]; } } printf("Prepare for data adjustment..."); debug_mt(mt); for (i = 0; i < mt.height; i ++) { for (j = 0; j < mt.height; j ++) { if (temp[i][j] == 0 && mt.row_lined[i] == 1 && mt.col_lined[j] == 1) { temp[i][j] = mt.cost[i][j] + min_d; mt.cost[i][j] = temp[i][j]; } else if (temp[i][j] == 1) { temp[i][j] -= min_d; mt.cost[i][j] = temp[i][j]; } } } printf("Data after adjustment:"); debug_mt(mt); calc_zeros(mt); select_zeros(mt); }void output_result(matrix &mt) { int i = 0, total = 0; printf("\nComputed Result:\n"); for (i = 0; i < mt.result_idx; i ++) { total += mt.ori_cost[mt.result[i][0]][mt.result[i][1]]; printf("(%d, %d)[%d] -> ", mt.result[i][0], mt.result[i][1], mt.ori_cost[mt.result[i][0]][mt.result[i][1]]); } printf("The Optimized Result: %d", total); }matrix matrix_input() { matrix mt; int workers = 0, jobs = 0, i = 0, j = 0; char w = 0; printf("Hungarian Method for Integer Programmin' (Minimal Optimization):\n"); //Programmed by Sirius Ding. THX. printf("Input the number of work units ( should between 1 to %d):\n", MAX_SIZE); scanf("%d", &workers); while(workers < 1 || workers > MAX_SIZE) { printf("Valid input required, again, please:\n"); scanf("%d", &workers); } printf("Input the number of work projects( should between 1 to %d):\n", MAX_SIZE); scanf("%d", &jobs); while(jobs < 1 || jobs > MAX_SIZE) { printf("Valid input required, again, please:\n"); scanf("%d", &jobs); } printf("Please input a matrix with dimension: %d rows %d columns.\nUse `space` to separate elements in the same row, and `enter` to switch to next row:\n",workers,jobs); for(i = 0; i < workers; i ++) { for(j = 0; j < jobs; j ++) { scanf("%d", &mt.cost[i][j]); mt.ori_cost[i][j] = mt.cost[i][j]; } } printf("Finished Matrix Input, Press Enter to continue."); scanf("%c", &w); if(jobs > workers) { for(i = workers; i < jobs; i ++) { for(j = 0; j < jobs; j ++) { mt.cost[i][j] = 0; mt.ori_cost[i][j] = 0; } } } else if(workers > jobs) { for(i = 0; i < workers; i ++) { for(j = jobs;j < workers; j ++) { mt.cost[i][j]=0; mt.ori_cost[i][j]=0; } } } mt.height = (workers > jobs) ? workers : jobs; return mt; }void calc_zeros(matrix &mt) { int i = 0, j = 0, k = 0; for(i = 0; i < mt.height; i ++) { k = mt.cost[i][0]; mt.row_zeros[i] = 0; mt.row_lined[i] = 0; mt.col_lined[i] = 0; if (k == 0) continue; for(j = 1; j < mt.height; j ++) if(mt.cost[i][j] < k) k = mt.cost[i][j]; if (k == 0) continue; for(j = 0; j < mt.height; j ++) mt.cost[i][j] = mt.cost[i][j] - k; } for(j = 0; j < mt.height; j++) { k = mt.cost[0][j]; mt.col_zeros[j] = 0; if (k == 0) continue; for(i = 1; i < mt.height; i ++) if(mt.cost[i][j] < k) k = mt.cost[i][j]; if (k == 0) continue; for(i = 0; i < mt.height; i ++) mt.cost[i][j] = mt.cost[i][j] - k; } mt.zeros = 0; for (i = 0; i < mt.height; i ++) { for (j = 0; j < mt.height; j ++) { if (mt.cost[i][j] == 0) { mt.row_zeros[i] ++; mt.col_zeros[j] ++; mt.zeros ++; } } } } void dual_optimal(matrix &mt) { int i = 0, j = 0, k = 0, t = 0, row_min = 0; int u[MAX_SIZE] = {0}, v[MAX_SIZE] = {0}; int u_idx_i = 0, u_idx_j = 0, dual_optimal = 0, coef = 0; for (i = 0; i < mt.result_idx; i ++) { u_idx_i = mt.result[i][0]; u_idx_j = mt.result[i][1]; t = mt.ori_cost[u_idx_i][u_idx_j]; row_min = mt.ori_cost[u_idx_i][0]; for (k = 0; k < mt.height; k ++) { if (mt.ori_cost[u_idx_i][k] < row_min) row_min = mt.ori_cost[u_idx_i][k]; } for (j = 0; j <= t; j ++) { if (j <= row_min && t - j <= row_min) { u[u_idx_i] = j; v[u_idx_j] = t - j; } } } for (i = 0; i < mt.height; i ++) coef += mt.ori_cost[i][i] - u[i] - v[i]; printf("\nDual Optimal listing:\n"); for (i = 0; i < mt.height; i ++) { dual_optimal += u[i] + v[i]; printf("u*(%d) = %3d, v*(%d) = %3d\n", i, u[i], i, v[i]); } printf("Dual Optimal %d \nAdjustment coef. is %d \n", dual_optimal, coef); }int main(int argc, char * argv[]) { matrix mt; mt = matrix_input(); debug_mt(mt); calc_zeros(mt); debug_mt(mt); select_zeros(mt); dual_optimal(mt); return 0; }
|
|
|
|