Code Duplication    Length = 51-51 lines in 2 locations

src/main/java/it/cnr/istc/pst/platinum/ai/framework/parameter/csp/solver/choco/v4/ChocoSolver.java 2 locations

@@ 486-536 (lines=51) @@
483
	 * @param bind
484
	 * @return
485
	 */
486
	private Constraint doCreateExcludeCSPConstraint(ExcludeParameterConstraint bind)
487
	{
488
		// CSP constraint
489
		Constraint cons;
490
		// get reference parameter
491
		Parameter<?> param = bind.getReference();
492
		// check if parameter variable exists
493
		if (!this.variables.containsKey(param)) {
494
			throw new RuntimeException("Unknown parameter variable - " + param);
495
		}
496
		
497
		// check parameter type 
498
		switch(param.getType())
499
		{
500
			// binding to enumeration parameter
501
			case ENUMERATION_PARAMETER_TYPE : 
502
			{
503
				// get parameter
504
				EnumerationParameter p = (EnumerationParameter) param;
505
				// get variable
506
				IntVar var = this.variables.get(p);
507
				// get binding value
508
				String value = (String) bind.getValue();
509
				// get related index
510
				int index = p.getDomain().getIndex(value);
511
				// create constraint 
512
				cons = this.model.arithm(var, "!=", index);
513
			}	
514
			break;
515
				
516
			// binding numeric variable
517
			case NUMERIC_PARAMETER_TYPE : 
518
			{
519
				// get parameter 
520
				NumericParameter p = (NumericParameter) param;
521
				// get variable 
522
				IntVar var = this.variables.get(p);
523
				// get binding value
524
				int value = (int) bind.getValue();
525
				// create constraint
526
				cons = this.model.arithm(var, "!=", value);
527
			}
528
			break;
529
				
530
			default : {
531
				throw new RuntimeException("Unknown parameter type - " + param.getType());
532
			}
533
		}
534
		
535
		// get create CSP constraint
536
		return cons;
537
	}
538
	
539
	/**
@@ 428-478 (lines=51) @@
425
	 * @param bind
426
	 * @return
427
	 */
428
	private Constraint doCreateBindCSPConstraint(BindParameterConstraint bind)
429
	{
430
		// CSP constraint
431
		Constraint cons;
432
		// get reference parameter
433
		Parameter<?> param = bind.getReference();
434
		// check if parameter variable exists
435
		if (!this.variables.containsKey(param)) {
436
			throw new RuntimeException("Unknown parameter variable - " + param);
437
		}
438
		
439
		// check parameter type 
440
		switch(param.getType())
441
		{
442
			// binding to enumeration parameter
443
			case ENUMERATION_PARAMETER_TYPE : 
444
			{
445
				// get parameter
446
				EnumerationParameter p = (EnumerationParameter) param;
447
				// get variable
448
				IntVar var = this.variables.get(p);
449
				// get binding value
450
				String value = (String) bind.getValue();
451
				// get related index
452
				int index = p.getDomain().getIndex(value);
453
				// create constraint 
454
				cons = this.model.arithm(var, "=", index);
455
			}	
456
			break;
457
				
458
			// binding numeric variable
459
			case NUMERIC_PARAMETER_TYPE : 
460
			{
461
				// get parameter 
462
				NumericParameter p = (NumericParameter) param;
463
				// get variable 
464
				IntVar var = this.variables.get(p);
465
				// get binding value
466
				int value = Integer.parseInt(bind.getValue().toString());
467
				// create constraint
468
				cons = this.model.arithm(var, "=", value);
469
			}
470
			break;
471
				
472
			default : {
473
				throw new RuntimeException("Unknown parameter type - " + param.getType());
474
			}
475
		}
476
		
477
		// get create CSP constraint
478
		return cons;
479
	}
480
	
481
	/**