昆山做网站怎么做,淄川区住房和城乡建设局网站,婚庆公司排名前十,做网站的请示python虽然不是完全为数学建模而生的#xff0c;但是它完整的库让它越来越适合建模了。 - 线性规划#xff1a;使用scipy.optimize.linprog()函数
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1], [1, 2]]
b [6, 4]
x0_bounds (None, None)
x1_bound…python虽然不是完全为数学建模而生的但是它完整的库让它越来越适合建模了。 - 线性规划使用scipy.optimize.linprog()函数
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1], [1, 2]]
b [6, 4]
x0_bounds (None, None)
x1_bounds (-3, None)
res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs)
print(res)- 整数规划使用scipy.optimize.linprog()函数并将目标函数系数转换为整数
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1], [1, 2]]
b [6, 4]
x0_bounds (None, None)
x1_bounds (-3, None)
res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs, integerTrue)
print(res)- 多元规划使用scipy.optimize.linprog()函数
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1, 1], [1, 2, 3]]
b [6, 4, 5]
x0_bounds (None, None, None)
x1_bounds (-3, -3, -3)
res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs)
print(res)- 二次规划使用scipy.optimize.linprog()函数并将目标函数系数转换为平方项
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1], [1, 2]]
b [6, 4]
x0_bounds (None, None)
x1_bounds (-3, None)
res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs, square_rootTrue)
print(res)- 遗传算法使用DEAP库
python
from deap import base, creator, tools, algorithms
import randomcreator.create(FitnessMin, base.Fitness, weights(-1.0,))
creator.create(Individual, list, fitnesscreator.FitnessMin)toolbox base.Toolbox()
toolbox.register(attr_bool, random.randint, 0, 1)
toolbox.register(individual, tools.initRepeat, creator.Individual, toolbox.attr_bool, n100)
toolbox.register(population, tools.initRepeat, list, toolbox.individual)def evalOneMax(individual):return sum(individual),toolbox.register(evaluate, evalOneMax)
toolbox.register(mate, tools.cxTwoPoint)
toolbox.register(mutate, tools.mutFlipBit, indpb0.05)
toolbox.register(select, tools.selTournament, tournsize3)population toolbox.population(n300)
algorithms.eaSimple(population, toolbox, cxpb0.5, mutpb0.2, ngen40)- 动态规划使用scipy.optimize.linprog()函数并将目标函数转换为动态规划问题
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1], [1, 2]]
b [6, 4]
x0_bounds (None, None)
x1_bounds (-3, None)
res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs)
print(res)- 贪心算法使用scipy.optimize.linprog()函数并将目标函数转换为贪心策略
python
from scipy.optimize import linprogc [-1, 4]
A [[-3, 1], [1, 2]]
b [6, 4]
x0_bounds (None, None)
x1_bounds (-3, None)
res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs, options{disp: True})
while not res.success:if not res.fun:print(Objective function value is 0 at point %s % res.x)breakif res.status 4:print(The algorithm could not find a feasible solution for the problem)breakprint(res)res linprog(c, A_ubA, b_ubb, bounds[x0_bounds, x1_bounds], methodhighs, options{disp: True})
print(res)下次再更新一些高难度的常见算法。