#include<iostream>
#define INF 65535
using namespace std;
class Shop{ //商店类
public:
double *w; //商店内每个物品的质量
double *v; //商店内每个物品的价格
};
class Tool{ //代组装机器类
public:
Shop *shop; //商店数组
int m; //商店个数
int num; //零件个数
int v; //最大价格
int bestw; //最小质量
int tempw; //当前质量
int tempv; //当前价格
int *best_step; //最优方案
int *temp_step; //当前方案
int *min_each_depth; //对于每个零件能得到的最小的质量
public:
/* 获取机器内每个零件的最小质量便于计算上界函数 */
int Min(int depth){
int min = shop[1].w[depth];
for(int i = 1;i <= m;i++)
if(shop[i].w[depth] < min)
min = shop[i].w[depth];
return min;
}
/* 初始化 */
void Initial(){
cout<<"please input the number of the tools and the nomber of shops and the Maximum price: "<<endl;
cin>>num>>m>>v;
best_step = new int[num * 2];
temp_step
回溯法实现最小重量机器设计
最新推荐文章于 2022-12-11 22:46:52 发布
本文探讨了如何运用回溯法来解决最小重量机器设计的问题。通过详细的步骤解析,阐述了如何构建问题的约束条件,并利用回溯策略进行有效的搜索,最终找到最优解。文章还讨论了回溯法在解决这类优化问题中的优势和适用场景。
摘要由CSDN通过智能技术生成