Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Beispiel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ling Jin
Beispiel
Commits
a04d1df9
Commit
a04d1df9
authored
2 years ago
by
Ling Jin
Browse files
Options
Downloads
Patches
Plain Diff
The first commit 1
parent
50f0570d
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
.idea/.name
+1
-0
1 addition, 0 deletions
.idea/.name
.idea/Example.iml
+0
-0
0 additions, 0 deletions
.idea/Example.iml
.idea/modules.xml
+1
-1
1 addition, 1 deletion
.idea/modules.xml
.idea/vcs.xml
+1
-1
1 addition, 1 deletion
.idea/vcs.xml
Example.py
+35
-0
35 additions, 0 deletions
Example.py
with
38 additions
and
2 deletions
.idea/.name
0 → 100644
+
1
−
0
View file @
a04d1df9
Example.py
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.idea/
pythonProject
.iml
→
.idea/
Example
.iml
+
0
−
0
View file @
a04d1df9
File moved
This diff is collapsed.
Click to expand it.
.idea/modules.xml
+
1
−
1
View file @
a04d1df9
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<project
version=
"4"
>
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/
pythonProject
.iml"
filepath=
"$PROJECT_DIR$/.idea/
pythonProject
.iml"
/>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/
Example
.iml"
filepath=
"$PROJECT_DIR$/.idea/
Example
.iml"
/>
</modules>
</modules>
</component>
</component>
</project>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
.idea/vcs.xml
+
1
−
1
View file @
a04d1df9
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<project
version=
"4"
>
<component
name=
"VcsDirectoryMappings"
>
<component
name=
"VcsDirectoryMappings"
>
<mapping
directory=
"
$PROJECT_DIR$
"
vcs=
"Git"
/>
<mapping
directory=
""
vcs=
"Git"
/>
</component>
</component>
</project>
</project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
main
.py
→
Example
.py
+
35
−
0
View file @
a04d1df9
<<<<<<<
HEAD
#导入包
#pyomo environment
from
pyomo.environ
import
*
from
pyomo.environ
import
*
#pyomo optimization
from
pyomo.opt
import
SolverFactory
from
pyomo.opt
import
SolverFactory
#实例化一个具体model,一般的最优化问题用到的都是concrete model,而不是abstract model。
#create a model 实例化类
model
=
ConcreteModel
()
model
=
ConcreteModel
()
#declare decision variables 宣布决策变量
#domain 域
model
.
x
=
Var
(
domain
=
NonNegativeReals
)
model
.
x
=
Var
(
domain
=
NonNegativeReals
)
model
.
y
=
Var
(
domain
=
NonNegativeReals
)
model
.
y
=
Var
(
domain
=
NonNegativeReals
)
#对于没有index的版本,直接列公式即可。
#expr是objective function的公式,sense是我们要最大化还是最小化
model
.
obj
=
Objective
(
expr
=
3
*
model
.
x
+
4
*
model
.
y
,
sense
=
minimize
)
model
.
obj
=
Objective
(
expr
=
3
*
model
.
x
+
4
*
model
.
y
,
sense
=
minimize
)
#declare constraint 宣布约束条件
model
.
con1
=
Constraint
(
expr
=
2
*
model
.
x
+
model
.
y
>=
15
)
model
.
con1
=
Constraint
(
expr
=
2
*
model
.
x
+
model
.
y
>=
15
)
model
.
con2
=
Constraint
(
expr
=
model
.
x
+
2
*
model
.
y
>=
17
)
model
.
con2
=
Constraint
(
expr
=
model
.
x
+
2
*
model
.
y
>=
17
)
model
.
con3
=
Constraint
(
expr
=
model
.
x
+
model
.
y
>=
10
)
model
.
con3
=
Constraint
(
expr
=
model
.
x
+
model
.
y
>=
10
)
result
=
SolverFactory
(
"
glpk
"
).
solve
(
model
)
#SolverFactory通过使用给出的求解器名称的参数用来创建执行优化的对象。
result
=
SolverFactory
(
"
gurobi
"
).
solve
(
model
)
#pprint():Data pretty printer。模块提供了美化打印任意python数据类型的功能,让显示结果显得更加漂亮"
#print()输出结果都在一行,不方便查看,而pprint采用了分行打印输出
model
.
pprint
()
model
.
pprint
()
#solve函数将结果加载到model中,因此以下一行写出更新后的值。
model
.
display
()
model
.
display
()
=======
l
=
[
'
a
'
,
'
x
'
,
'
b
'
,
'
x
'
,
'
c
'
,
'
x
'
]
print
(
l
)
l
.
pop
(
2
)
# remove the first item with value 'x'
print
(
l
)
>>>>>>>
origin
/
main
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment