1
+ use crate :: builder:: cons:: ConsBuilder ;
1
2
use crate :: builder:: CanBeAddedToModel ;
2
3
use crate :: constraint:: Constraint ;
3
4
use crate :: eventhdlr:: Eventhdlr ;
@@ -161,7 +162,7 @@ impl Model<ProblemCreated> {
161
162
///
162
163
/// # Returns
163
164
///
164
- /// A reference-counted pointer to the new variable.
165
+ /// The created `Variable`
165
166
///
166
167
/// # Panics
167
168
///
@@ -400,7 +401,7 @@ impl Model<Solving> {
400
401
///
401
402
/// # Returns
402
403
///
403
- /// A reference-counted pointer to the new variable.
404
+ /// The created `Variable`
404
405
///
405
406
/// # Panics
406
407
///
@@ -425,10 +426,6 @@ impl Model<Solving> {
425
426
}
426
427
427
428
/// Returns the current node of the model.
428
- ///
429
- /// # Panics
430
- ///
431
- /// This method panics if not called in the `Solving` state, it should only be used from plugins implementations.
432
429
pub fn focus_node ( & self ) -> Node {
433
430
let scip_node = self . scip . focus_node ( ) . expect ( "Failed to get focus node" ) ;
434
431
Node {
@@ -438,10 +435,6 @@ impl Model<Solving> {
438
435
}
439
436
440
437
/// Creates a new child node of the current node and returns it.
441
- ///
442
- /// # Panics
443
- ///
444
- /// This method panics if not called from plugins implementations.
445
438
pub fn create_child ( & mut self ) -> Node {
446
439
let node_ptr = self
447
440
. scip
@@ -466,7 +459,7 @@ impl Model<Solving> {
466
459
///
467
460
/// # Returns
468
461
///
469
- /// This function returns a reference-counted smart pointer (`Rc`) to the created `Variable` instance.
462
+ /// The created `Variable`
470
463
pub fn add_priced_var (
471
464
& mut self ,
472
465
lb : f64 ,
@@ -486,13 +479,98 @@ impl Model<Solving> {
486
479
}
487
480
}
488
481
482
+ /// Locally adds a constraint to the current node and its subnodes.
483
+ ///
484
+ /// # Arguments
485
+ ///
486
+ /// * `cons` - The constraint to add (can be built by calling the cons() function).
487
+ ///
488
+ /// # Returns
489
+ ///
490
+ /// The new constraint
491
+ ///
492
+ /// # Panics
493
+ ///
494
+ /// This method panics if the constraint cannot be created in the current state.
495
+ pub fn add_cons_local ( & mut self , cons : & ConsBuilder ) -> Constraint {
496
+ let vars: Vec < & Variable > = cons. coefs . iter ( ) . map ( |( var, _) | * var) . collect ( ) ;
497
+ let coefs: Vec < f64 > = cons. coefs . iter ( ) . map ( |( _, coef) | * coef) . collect ( ) ;
498
+
499
+ let cons = self
500
+ . scip
501
+ . create_cons (
502
+ None ,
503
+ vars,
504
+ & coefs,
505
+ cons. lhs ,
506
+ cons. rhs ,
507
+ cons. name . unwrap_or ( "" ) ,
508
+ true ,
509
+ )
510
+ . expect ( "Failed to create constraint in state Solving" ) ;
511
+ Constraint {
512
+ raw : cons,
513
+ scip : self . scip . clone ( ) ,
514
+ }
515
+ }
516
+
517
+ /// Locally adds a constraint to a given node and its children.
518
+ ///
519
+ /// # Arguments
520
+ ///
521
+ /// * `node` - The node to which the constraint should be added.
522
+ /// * `cons` - The constraint to add.
523
+ ///
524
+ /// # Returns
525
+ ///
526
+ /// The created `Constraint`.
527
+ ///
528
+ /// # Panics
529
+ ///
530
+ /// This method panics if the constraint cannot be created in the current state.
531
+ pub fn add_cons_node ( & mut self , node : & Node , cons : & ConsBuilder ) -> Constraint {
532
+ let vars: Vec < & Variable > = cons. coefs . iter ( ) . map ( |( var, _) | * var) . collect ( ) ;
533
+ let coefs: Vec < f64 > = cons. coefs . iter ( ) . map ( |( _, coef) | * coef) . collect ( ) ;
534
+
535
+ let cons = self
536
+ . scip
537
+ . create_cons (
538
+ Some ( node) ,
539
+ vars,
540
+ & coefs,
541
+ cons. lhs ,
542
+ cons. rhs ,
543
+ cons. name . unwrap_or ( "" ) ,
544
+ true ,
545
+ )
546
+ . expect ( "Failed to create constraint in state ProblemCreated" ) ;
547
+
548
+ Constraint {
549
+ raw : cons,
550
+ scip : self . scip . clone ( ) ,
551
+ }
552
+ }
553
+
554
+ /// Returns the number of added constraints to the given nodes
555
+ ///
556
+ /// # Arguments
557
+ ///
558
+ /// * `node` - The node to which the constraints were added.
559
+ ///
560
+ /// # Returns
561
+ ///
562
+ /// The number of added constraints.
563
+ pub fn node_get_n_added_conss ( & mut self , node : & Node ) -> usize {
564
+ self . scip . node_get_n_added_conss ( node)
565
+ }
566
+
489
567
/// Gets the variable in current problem given its index (in the problem).
490
568
///
491
569
/// # Arguments
492
570
/// * `var_prob_id` - The index of the variable in the problem.
493
571
///
494
572
/// # Returns
495
- /// A reference-counted pointer to the variable .
573
+ /// The `Variable` if it exists, otherwise `None` .
496
574
pub fn var_in_prob ( & self , var_prob_id : usize ) -> Option < Variable > {
497
575
unsafe {
498
576
ScipPtr :: var_from_id ( self . scip . raw , var_prob_id) . map ( |v| Variable {
@@ -1023,7 +1101,7 @@ impl<S: ModelStageProblemOrSolving> ProblemOrSolving for Model<S> {
1023
1101
assert_eq ! ( vars. len( ) , coefs. len( ) ) ;
1024
1102
let cons = self
1025
1103
. scip
1026
- . create_cons ( vars, coefs, lhs, rhs, name)
1104
+ . create_cons ( None , vars, coefs, lhs, rhs, name, false )
1027
1105
. expect ( "Failed to create constraint in state ProblemCreated" ) ;
1028
1106
1029
1107
Constraint {
@@ -1068,7 +1146,7 @@ impl<S: ModelStageProblemOrSolving> ProblemOrSolving for Model<S> {
1068
1146
///
1069
1147
/// # Returns
1070
1148
///
1071
- /// A reference-counted pointer to the new constraint .
1149
+ /// The new `Constraint` .
1072
1150
///
1073
1151
/// # Panics
1074
1152
///
@@ -1095,7 +1173,7 @@ impl<S: ModelStageProblemOrSolving> ProblemOrSolving for Model<S> {
1095
1173
///
1096
1174
/// # Returns
1097
1175
///
1098
- /// A reference-counted pointer to the new constraint.
1176
+ /// The created `Constraint`
1099
1177
///
1100
1178
/// # Panics
1101
1179
///
@@ -1123,7 +1201,7 @@ impl<S: ModelStageProblemOrSolving> ProblemOrSolving for Model<S> {
1123
1201
///
1124
1202
/// # Returns
1125
1203
///
1126
- /// A reference-counted pointer to the new constraint.
1204
+ /// The created `Constraint`
1127
1205
///
1128
1206
/// # Panics
1129
1207
///
@@ -1157,7 +1235,7 @@ impl<S: ModelStageProblemOrSolving> ProblemOrSolving for Model<S> {
1157
1235
///
1158
1236
/// # Returns
1159
1237
///
1160
- /// A reference-counted pointer to the new constraint.
1238
+ /// The created `Constraint`
1161
1239
///
1162
1240
/// # Panics
1163
1241
///
0 commit comments