Files
feed-formula-calculator/feed_formula_calculator.py
2025-09-23 00:53:10 +08:00

37 lines
2.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import optimize_feed
# 示例调用
if __name__ == "__main__":
# 原料数据(加工后,单位:%或MJ/kg价格元/吨)
ingredients = {
'构树叶': {'蛋白': 15, '能量': 9, '纤维': 10, '赖氨酸': 0.5, '蛋氨酸': 0.1, '': 1.5, '': 0.2, '价格': 600},
'玉米胚芽': {'蛋白': 11, '能量': 13, '纤维': 7, '赖氨酸': 0.4, '蛋氨酸': 0.2, '': 0.1, '': 0.3,
'价格': 1700},
'麦麸': {'蛋白': 15, '能量': 10, '纤维': 12, '赖氨酸': 0.4, '蛋氨酸': 0.2, '': 0.1, '': 1.0, '价格': 1300},
'米糠': {'蛋白': 13, '能量': 11, '纤维': 10, '赖氨酸': 0.4, '蛋氨酸': 0.2, '': 0.1, '': 1.5, '价格': 1100},
'牧草': {'蛋白': 17, '能量': 8.5, '纤维': 20, '赖氨酸': 0.6, '蛋氨酸': 0.2, '': 1.2, '': 0.3, '价格': 800},
'玉米': {'蛋白': 9, '能量': 13.5, '纤维': 2.5, '赖氨酸': 0.3, '蛋氨酸': 0.17, '': 0.02, '': 0.3,
'价格': 2367},
'豆粕': {'蛋白': 46, '能量': 10.5, '纤维': 4, '赖氨酸': 2.8, '蛋氨酸': 0.6, '': 0.3, '': 0.7, '价格': 3300},
'植物油': {'蛋白': 0, '能量': 36, '纤维': 0, '赖氨酸': 0, '蛋氨酸': 0, '': 0, '': 0, '价格': 7500},
'赖氨酸': {'蛋白': 78, '能量': 0, '纤维': 0, '赖氨酸': 78, '蛋氨酸': 0, '': 0, '': 0, '价格': 15000},
'蛋氨酸': {'蛋白': 99, '能量': 0, '纤维': 0, '赖氨酸': 0, '蛋氨酸': 99, '': 0, '': 0, '价格': 25000},
'预混料': {'蛋白': 0, '能量': 0, '纤维': 0, '赖氨酸': 0, '蛋氨酸': 0, '': 10, '': 5, '价格': 3000}
}
requirements = {
'蛋白_下限': 17,
'能量_下限': 13,
'纤维_上限': 5,
'赖氨酸_下限': 0.75,
'蛋氨酸_下限': 0.25,
'钙_下限': 0.5,
'磷_下限': 0.4
}
# 运行优化
result = optimize_feed.optimize_feed(requirements, ingredients, ['比例', '成本'], 'min')
print("优化结果:")
for key, value in result.items():
print(f"{key}: {value}")