回答編集履歴
1
見直しキャンペーン中
test
CHANGED
@@ -1,27 +1,51 @@
|
|
1
|
-
エラー文で検索したところ、`Solution solution = context.Solve();`と回答がありました。
|
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)
|
2
3
|
|
4
|
+
```cs
|
5
|
+
using System;
|
6
|
+
using Microsoft.SolverFoundation.Services;
|
3
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
|
+
```
|
4
39
|
|
5
40
|
実行結果
|
6
|
-
|
7
41
|
```
|
8
|
-
|
9
42
|
===Solution Details===
|
10
|
-
|
11
43
|
Goals:
|
12
|
-
|
13
44
|
Goal: 15
|
14
45
|
|
15
|
-
|
16
|
-
|
17
46
|
Decisions:
|
18
|
-
|
19
47
|
b2: 30
|
20
|
-
|
21
48
|
b3: 2
|
22
|
-
|
23
49
|
b4: 15
|
24
|
-
|
25
50
|
```
|
26
|
-
|
27
51
|
私は全く使ったことないので、これでいいのかわかりません。
|