diff --git a/_sources/examples/optimal_control_rocket.md.txt b/_sources/examples/optimal_control_rocket.md.txt index ffbbd0c..42cce76 100644 --- a/_sources/examples/optimal_control_rocket.md.txt +++ b/_sources/examples/optimal_control_rocket.md.txt @@ -111,7 +111,9 @@ After solving the problem, we can plot the results. ```{code-cell} model.optimize() +``` +```{code-cell} h_value = [] for i in range(T): h_value.append(model.get_value(h[i])) diff --git a/_sources/examples/optimal_power_flow.md.txt b/_sources/examples/optimal_power_flow.md.txt index 4035bd6..c2949c3 100644 --- a/_sources/examples/optimal_power_flow.md.txt +++ b/_sources/examples/optimal_power_flow.md.txt @@ -236,7 +236,9 @@ After optimization, we can retrieve the optimal solution: ```{code-cell} model.optimize() +``` +```{code-cell} print(model.get_model_attribute(poi.ModelAttribute.TerminationStatus)) P_value = P.map(model.get_value) diff --git a/_sources/nonlinear.md.txt b/_sources/nonlinear.md.txt index cb9a2f1..466d29b 100644 --- a/_sources/nonlinear.md.txt +++ b/_sources/nonlinear.md.txt @@ -177,7 +177,9 @@ model.add_nl_constraint(con_f, nlfunc.Vars(x=x,y=y), ub = [4.0, -1.0]) model.add_nl_objective(obj_f, nlfunc.Vars(x=x,y=y)) model.optimize() +``` +```{code-cell} x_value = model.get_value(x) y_value = model.get_value(y) @@ -241,7 +243,9 @@ rosenbrock_f = model.register_function(rosenbrock) model.add_nl_objective(rosenbrock_f, nlfunc.Vars(x=x, y=y)) model.optimize() +``` +```{code-cell} x_value = model.get_value(x) y_value = model.get_value(y) @@ -286,7 +290,9 @@ for i in range(N): model.add_linear_constraint(t[i+1] - t[i] - 0.5 * h * u[i+1] - 0.5 * h * u[i] , poi.Eq, 0.0) model.optimize() +``` +```{code-cell} objective_value = model.get_model_attribute(poi.ModelAttribute.ObjectiveValue) print(f"Objective value: {objective_value}") diff --git a/constraint.html b/constraint.html index f6689de..a4e8cef 100644 --- a/constraint.html +++ b/constraint.html @@ -304,12 +304,12 @@
2024-11-27 17:18:09 [INFO] checks license for COPT v7.2.2 20241023
-2024-11-27 17:18:09 [WARN] no license files in current working folder: /home/runner/work/PyOptInterface/PyOptInterface/docs/source
-2024-11-27 17:18:09 [WARN] no license files in binary folder: /opt/hostedtoolcache/Python/3.12.7/x64/bin
-2024-11-27 17:18:09 [WARN] no license files in HOME folder: /home/runner/copt
-2024-11-27 17:18:09 [INFO] empty environment variable: COPT_LICENSE_DIR
-2024-11-27 17:18:09 [WARN] no license files in EV 'COPT_LICENSE_DIR':
+2024-11-27 17:28:19 [INFO] checks license for COPT v7.2.2 20241023
+2024-11-27 17:28:19 [WARN] no license files in current working folder: /home/runner/work/PyOptInterface/PyOptInterface/docs/source
+2024-11-27 17:28:19 [WARN] no license files in binary folder: /opt/hostedtoolcache/Python/3.12.7/x64/bin
+2024-11-27 17:28:19 [WARN] no license files in HOME folder: /home/runner/copt
+2024-11-27 17:28:19 [INFO] empty environment variable: COPT_LICENSE_DIR
+2024-11-27 17:28:19 [WARN] no license files in EV 'COPT_LICENSE_DIR':
No license found. Starting COPT with size limitations for non-commercial use
Please apply for a license from www.shanshu.ai/copt
diff --git a/examples/optimal_control_rocket.html b/examples/optimal_control_rocket.html
index 5d8b18f..53fcdfa 100644
--- a/examples/optimal_control_rocket.html
+++ b/examples/optimal_control_rocket.html
@@ -394,12 +394,6 @@ Implementation
model.optimize()
-
-h_value = []
-for i in range(T):
- h_value.append(model.get_value(h[i]))
-
-print("Optimal altitude: ", h_value[-1])
@@ -483,11 +477,26 @@ Implementation
+
+h_value = []
+for i in range(T):
+ h_value.append(model.get_value(h[i]))
+
+print("Optimal altitude: ", h_value[-1])
+
+
+
+
+Optimal altitude: 1.012779392216388
diff --git a/examples/optimal_power_flow.html b/examples/optimal_power_flow.html
index 5a075c0..fa70025 100644
--- a/examples/optimal_power_flow.html
+++ b/examples/optimal_power_flow.html
@@ -520,15 +520,6 @@ Implementation
model.optimize()
-
-print(model.get_model_attribute(poi.ModelAttribute.TerminationStatus))
-
-P_value = P.map(model.get_value)
-
-print("Optimal active power output of the generators:")
-
-for i in range(N_gen):
- print(f"Generator {i}: {P_value[i]}")
@@ -592,13 +583,6 @@ Implementation
+
+print(model.get_model_attribute(poi.ModelAttribute.TerminationStatus))
+
+P_value = P.map(model.get_value)
+
+print("Optimal active power output of the generators:")
+
+for i in range(N_gen):
+ print(f"Generator {i}: {P_value[i]}")
+
+
+
+
+TerminationStatusCode.LOCALLY_SOLVED
+Optimal active power output of the generators:
+Generator 0: 0.4
+Generator 1: 1.7
+Generator 2: 1.9623464660959797
+Generator 3: 0.0
+Generator 4: 6.0
+
+
+
+
As shown by the result, the generator with less cost efficient has the highest active power output. The total generation power is also greater than the total demand due to the network loss.
diff --git a/expression.html b/expression.html
index a91013f..cb92b8c 100644
--- a/expression.html
+++ b/expression.html
@@ -361,8 +361,8 @@ Efficient expression construction
-CPU times: user 642 μs, sys: 99 μs, total: 741 μs
-Wall time: 744 μs
+CPU times: user 593 μs, sys: 129 μs, total: 722 μs
+Wall time: 726 μs
@@ -374,8 +374,8 @@ Efficient expression construction
-CPU times: user 18 ms, sys: 0 ns, total: 18 ms
-Wall time: 17.9 ms
+CPU times: user 17.6 ms, sys: 341 μs, total: 17.9 ms
+Wall time: 17.8 ms
diff --git a/nonlinear.html b/nonlinear.html
index f266b69..9822ada 100644
--- a/nonlinear.html
+++ b/nonlinear.html
@@ -483,11 +483,6 @@ Nonlinear constraints and objectivesmodel.add_nl_objective(obj_f, nlfunc.Vars(x=x,y=y))
model.optimize()
-
-x_value = model.get_value(x)
-y_value = model.get_value(y)
-
-print(f"x = {x_value}, y = {y_value}")
@@ -539,10 +534,8 @@ Nonlinear constraints and objectivesNumber of Iterations....: 10
+
+Number of Iterations....: 10
(scaled) (unscaled)
Objective...............: 5.4365636322427102e+00 5.4365636322427102e+00
@@ -559,7 +552,7 @@ Nonlinear constraints and objectives
+
+x_value = model.get_value(x)
+y_value = model.get_value(y)
+
+print(f"x = {x_value}, y = {y_value}")
+
+
+
+
+x = 0.9999999954612174, y = 0.9999999954612174
+
+
+
+
Nonlinear constraint can be declared by calling add_nl_constraint
method of the Model
object. The method accepts the registered function, the variables/parameters of the constraint, and the bounds of the constraint.
The variables of the constraint should be constructed by nlfunc.Vars
and the parameters should be constructed by nlfunc.Params
.
The bounds can be specified as a scalar or a list with the same length as the number of outputs of the function. If it is a scalar, the same bound will be applied to all outputs. If it is a list, each output will have its own bound.
@@ -631,11 +639,6 @@ Nonlinear constraints and objectivesmodel.add_nl_objective(rosenbrock_f, nlfunc.Vars(x=x, y=y))
model.optimize()
-
-x_value = model.get_value(x)
-y_value = model.get_value(y)
-
-print(f"x = {x_value}, y = {y_value}")
x_value = model.get_value(x)
+y_value = model.get_value(y)
+
+print(f"x = {x_value}, y = {y_value}")
+
x = 0.9999999999999899, y = 0.9999999999999792
+
objective_value = model.get_model_attribute(poi.ModelAttribute.ObjectiveValue)
+
+print(f"Objective value: {objective_value}")
+
Objective value: 350.0000000000032
+