teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/17 04:30

投稿

TN8001
TN8001

スコア10111

answer CHANGED
@@ -1,14 +1,51 @@
1
- エラー文で検索したところ、`Solution solution = context.Solve();`と回答がありました。[リンク](https://social.msdn.microsoft.com/Forums/en-US/db991a49-4034-4d7b-bc85-313f42255d12/optimal-portfolio-model-error?forum=solverfoundation)
2
-
3
- 実行結果
4
- ```
5
- ===Solution Details===
6
- Goals:
7
- Goal: 15
8
-
9
- Decisions:
10
- b2: 30
11
- b3: 2
12
- b4: 15
13
- ```
1
+ エラー文で検索したところ、`Solution solution = context.Solve();`と回答がありました。
2
+ [Optimal portfolio model - error](https://social.msdn.microsoft.com/Forums/en-US/db991a49-4034-4d7b-bc85-313f42255d12/optimal-portfolio-model-error)
3
+
4
+ ```cs
5
+ using System;
6
+ using Microsoft.SolverFoundation.Services;
7
+
8
+ namespace Questions217122
9
+ {
10
+ internal class Program
11
+ {
12
+ private static void Main()
13
+ {
14
+ var context = new SolverContext();
15
+ var model = context.CreateModel();
16
+
17
+ var b2 = new Decision(Domain.Integer, "b2");
18
+ var b3 = new Decision(Domain.Integer, "b3");
19
+ var b4 = new Decision(Domain.Integer, "b4");
20
+
21
+ model.AddDecision(b2);
22
+ model.AddDecision(b3);
23
+ model.AddDecision(b4);
24
+
25
+ model.AddConstraint("limit1", 10 <= b2 <= 30);
26
+ model.AddConstraint("limit2", 2 <= b3 <= 10);
27
+ model.AddConstraint("limit3", 2 <= b4 <= 100);
28
+ model.AddConstraint("limit4", b2 / b3 <= b4 <= b2 / b3);
29
+
30
+ model.AddGoal("Goal", GoalKind.Maximize, b4);
31
+
32
+ var solution = context.Solve();
33
+ var report = solution.GetReport();
34
+ Console.WriteLine(report);
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+ 実行結果
41
+ ```
42
+ ===Solution Details===
43
+ Goals:
44
+ Goal: 15
45
+
46
+ Decisions:
47
+ b2: 30
48
+ b3: 2
49
+ b4: 15
50
+ ```
14
51
  私は全く使ったことないので、これでいいのかわかりません。