摘要: 1、基于字典的创建规划问题 上篇中介绍了使用 LpVariable 对逐一定义每个决策变量,设定名称、类型和上下界,类似地对约束条件也需要逐一设置模型参数。在大规模的规划问题中,这样逐个定义变量和设置模型参数非常繁琐,效率很低。Pulp 库提供了一种快捷方式,可以结合 Python语言的循环和容器, 阅读全文
posted @ 2021-04-30 20:46 youcans 阅读(3114) 评论(0) 推荐(1) 编辑
摘要: 1、什么是线性规划 线性规划(Linear programming),在线性等式或不等式约束条件下求解线性目标函数的极值问题,常用于解决资源分配、生产调度和混合问题。例如: max fx = 2*x1 + 3*x2 - 5*x3 s.t. x1 + 3*x2 + x3 <= 12 2*x1 - 5* 阅读全文
posted @ 2021-04-28 14:48 youcans 阅读(4773) 评论(0) 推荐(1) 编辑
摘要: 1、最优化问题建模 最优化问题的三要素是决策变量、目标函数和约束条件。 (1)分析影响结果的因素是什么,确定决策变量 (2)决策变量与优化目标的关系是什么,确定目标函数 (3)决策变量所受的限制条件是什么,确定约束条件 最优化问题的建模,通常按照以下步骤进行: (1)问题定义,确定决策变量、目标函数 阅读全文
posted @ 2021-04-28 11:22 youcans 阅读(5348) 评论(0) 推荐(0) 编辑
摘要: 【练习51】矩阵转置 0. 题目: 矩阵的转置 1. 分析: 练习使用 for 循环嵌套,多维数组的表达。 2. 程序: #include <stdio.h> int main() { int inMatrix[10][10], outMatrix[10][10], rows, cols, i, j 阅读全文
posted @ 2021-04-19 14:09 youcans 阅读(460) 评论(0) 推荐(0) 编辑
摘要: 【练习41】字符串翻转 0. 题目: 字符串翻转 1. 分析: 学习递归思想和方法。 2. 程序: 方法一: #include <stdio.h> void reverseSentence(); int main() { printf("输入一个字符串(非中文): "); reverseSenten 阅读全文
posted @ 2021-04-18 19:02 youcans 阅读(333) 评论(0) 推荐(0) 编辑
摘要: 【练习31】判断质数 0. 题目: 判断质数 1. 分析: 质数(prime number),指大于 1的、且除 1 和本身以外没有其他因数的自然数。 2. 程序: #include <stdio.h> #include<math.h> int main() { int i, iNum, iFlag 阅读全文
posted @ 2021-04-12 15:41 youcans 阅读(567) 评论(0) 推荐(0) 编辑
摘要: 【练习21】计算自然数的和 0. 题目: 计算自然数的和 1. 分析: 练习使用 for 循环结构。for 循环允许一个执行指定次数的循环控制结构。 2. 程序: #include <stdio.h> int main() { int i, iNum, iSum; printf("输入一个正整数: 阅读全文
posted @ 2021-03-12 11:12 youcans 阅读(1073) 评论(0) 推荐(0) 编辑
摘要: 【练习11】计算 int, float, double 和 char 字节大小 0. 题目: 计算 int, float, double 和 char 字节大小 1. 分析: 使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。 sizeof 是单目操作 阅读全文
posted @ 2021-03-08 20:56 youcans 阅读(815) 评论(0) 推荐(0) 编辑
摘要: 【练习1】输出 "Hello, World!" 0. 题目: 输出 "Hello, World!" 1. 分析: 使用 printf() 输出 "Hello, World!"。 2. 程序: #include <stdio.h> int main() { printf("Hello, World!" 阅读全文
posted @ 2021-03-08 17:02 youcans 阅读(4116) 评论(0) 推荐(0) 编辑
摘要: 练习91: 题目: 时间函数举例1。 程序: if __name__ == '__main__': import time print (time.ctime(time.time())) print (time.asctime(time.localtime(time.time()))) print 阅读全文
posted @ 2021-03-08 16:59 youcans 阅读(252) 评论(0) 推荐(0) 编辑