@Test public void testEstimateEfficiency() { logger.info("estimateEfficiency"); Map<Object, DataEnvelopmentAnalysis.DeaRecord> id2DeaRecordMapInput = new LinkedHashMap<>(); id2DeaRecordMapInput.put("Depot1", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(40.0,55.0,30.0)), new FlatDataList(Arrays.asList(3.0,5.0)))); id2DeaRecordMapInput.put("Depot2", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(45.0,50.0,40.0)), new FlatDataList(Arrays.asList(2.5,4.5)))); id2DeaRecordMapInput.put("Depot3", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(55.0,45.0,30.0)), new FlatDataList(Arrays.asList(4.0,6.0)))); id2DeaRecordMapInput.put("Depot4", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(48.0,20.0,60.0)), new FlatDataList(Arrays.asList(6.0,7.0)))); id2DeaRecordMapInput.put("Depot5", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(28.0,50.0,25.0)), new FlatDataList(Arrays.asList(2.3,3.5)))); id2DeaRecordMapInput.put("Depot6", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(48.0,20.0,65.0)), new FlatDataList(Arrays.asList(4.0,6.5)))); id2DeaRecordMapInput.put("Depot7", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(80.0,65.0,57.0)), new FlatDataList(Arrays.asList(7.0,10.0)))); id2DeaRecordMapInput.put("Depot8", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(25.0,48.0,30.0)), new FlatDataList(Arrays.asList(4.4,6.4)))); id2DeaRecordMapInput.put("Depot9", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(45.0,64.0,42.0)), new FlatDataList(Arrays.asList(3.0,5.0)))); id2DeaRecordMapInput.put("Depot10", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(70.0,65.0,48.0)), new FlatDataList(Arrays.asList(5.0,7.0)))); id2DeaRecordMapInput.put("Depot11", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(45.0,65.0,40.0)), new FlatDataList(Arrays.asList(5.0,7.0)))); id2DeaRecordMapInput.put("Depot12", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(45.0,40.0,44.0)), new FlatDataList(Arrays.asList(2.0,4.0)))); id2DeaRecordMapInput.put("Depot13", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(65.0,25.0,35.0)), new FlatDataList(Arrays.asList(5.0,7.0)))); id2DeaRecordMapInput.put("Depot14", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(38.0,18.0,64.0)), new FlatDataList(Arrays.asList(4.0,4.0)))); id2DeaRecordMapInput.put("Depot15", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(20.0,50.0,15.0)), new FlatDataList(Arrays.asList(2.0,3.0)))); id2DeaRecordMapInput.put("Depot16", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(38.0,20.0,60.0)), new FlatDataList(Arrays.asList(3.0,6.0)))); id2DeaRecordMapInput.put("Depot17", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(68.0,64.0,54.0)), new FlatDataList(Arrays.asList(7.0,11.0)))); id2DeaRecordMapInput.put("Depot18", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(25.0,38.0,20.0)), new FlatDataList(Arrays.asList(4.0,6.0)))); id2DeaRecordMapInput.put("Depot19", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(45.0,67.0,32.0)), new FlatDataList(Arrays.asList(3.0,4.0)))); id2DeaRecordMapInput.put("Depot20", new DataEnvelopmentAnalysis.DeaRecord(new FlatDataList(Arrays.asList(57.0,60.0,40.0)), new FlatDataList(Arrays.asList(5.0,6.0)))); Map<Object, DataEnvelopmentAnalysis.DeaRecord> id2DeaRecordMapOutput = new LinkedHashMap<>(id2DeaRecordMapInput); DataEnvelopmentAnalysis instance = new DataEnvelopmentAnalysis(); AssociativeArray expResult = new AssociativeArray(); expResult.put("Depot1", 0.82038345105954); expResult.put("Depot2", 0.94174174174174); expResult.put("Depot3", 0.81481481481481); expResult.put("Depot4", 0.65279091769158); expResult.put("Depot5", 0.94655825212588); expResult.put("Depot6", 0.82278481012658); expResult.put("Depot7", 0.71111111111111); expResult.put("Depot8", 0.51685181698362); expResult.put("Depot9", 0.96344285053216); expResult.put("Depot10", 0.88888888888889); expResult.put("Depot11", 0.63128611170554); expResult.put("Depot12", 1); expResult.put("Depot13", 0.82539682539683); expResult.put("Depot14", 1); expResult.put("Depot15", 1); expResult.put("Depot16", 0.90909090909091); expResult.put("Depot17", 0.54949494949495); expResult.put("Depot18", 0.42007168458781); expResult.put("Depot19", 1); expResult.put("Depot20", 0.84444444444444); AssociativeArray result = instance.estimateEfficiency(id2DeaRecordMapInput, id2DeaRecordMapOutput); TestUtils.assetDoubleAssociativeArray(expResult, result); }
public AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput) { AssociativeArray evaluatedResults = new AssociativeArray(); List<LPSolver.LPConstraint> constraints = new ArrayList<>(); Integer totalColumns = null; boolean hasInput = false; for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapInput.entrySet()) { DeaRecord currentRecord = entry.getValue(); int currentColumns = currentRecord.getInput().length; boolean currentHasInput=(currentColumns > 0); currentColumns+=currentRecord.getOutput().length; if(totalColumns==null) { totalColumns=currentColumns; hasInput=currentHasInput; } else { if(totalColumns!=currentColumns) { throw new IllegalArgumentException("The input and output columns do not match in all records."); } if(hasInput!=currentHasInput) { throw new IllegalArgumentException("The input should be used in all records or in none."); } } if(hasInput==false) { constraints.add(new LPSolver.LPConstraint(currentRecord.getOutput(), LPSolver.LEQ, 1.0)); } else { double[] currentConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { currentConstraintBody[i]=conOutput[i]; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { currentConstraintBody[conOutput.length+i]=-conInput[i]; } constraints.add(new LPSolver.LPConstraint(currentConstraintBody, LPSolver.LEQ, 0.0)); } } for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapOutput.entrySet()) { Object currentRecordId = entry.getKey(); DeaRecord currentRecord = entry.getValue(); double[] objectiveFunction; if(hasInput==false) { objectiveFunction=currentRecord.getOutput(); } else { objectiveFunction = new double[totalColumns]; double[] denominatorConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { objectiveFunction[i]=conOutput[i]; denominatorConstraintBody[i]=0.0; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { objectiveFunction[conOutput.length+i]=0.0; denominatorConstraintBody[conOutput.length+i]=conInput[i]; } constraints.add(new LPSolver.LPConstraint(denominatorConstraintBody, LPSolver.EQ, 1.0)); } LPSolver.LPResult result = LPSolver.solve(objectiveFunction, constraints, true, true); Double objectiveValue = result.getObjectiveValue(); if(hasInput) { constraints.remove(constraints.size()-1); } evaluatedResults.put(currentRecordId, objectiveValue); } return evaluatedResults; }
DataEnvelopmentAnalysis { public AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput) { AssociativeArray evaluatedResults = new AssociativeArray(); List<LPSolver.LPConstraint> constraints = new ArrayList<>(); Integer totalColumns = null; boolean hasInput = false; for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapInput.entrySet()) { DeaRecord currentRecord = entry.getValue(); int currentColumns = currentRecord.getInput().length; boolean currentHasInput=(currentColumns > 0); currentColumns+=currentRecord.getOutput().length; if(totalColumns==null) { totalColumns=currentColumns; hasInput=currentHasInput; } else { if(totalColumns!=currentColumns) { throw new IllegalArgumentException("The input and output columns do not match in all records."); } if(hasInput!=currentHasInput) { throw new IllegalArgumentException("The input should be used in all records or in none."); } } if(hasInput==false) { constraints.add(new LPSolver.LPConstraint(currentRecord.getOutput(), LPSolver.LEQ, 1.0)); } else { double[] currentConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { currentConstraintBody[i]=conOutput[i]; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { currentConstraintBody[conOutput.length+i]=-conInput[i]; } constraints.add(new LPSolver.LPConstraint(currentConstraintBody, LPSolver.LEQ, 0.0)); } } for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapOutput.entrySet()) { Object currentRecordId = entry.getKey(); DeaRecord currentRecord = entry.getValue(); double[] objectiveFunction; if(hasInput==false) { objectiveFunction=currentRecord.getOutput(); } else { objectiveFunction = new double[totalColumns]; double[] denominatorConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { objectiveFunction[i]=conOutput[i]; denominatorConstraintBody[i]=0.0; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { objectiveFunction[conOutput.length+i]=0.0; denominatorConstraintBody[conOutput.length+i]=conInput[i]; } constraints.add(new LPSolver.LPConstraint(denominatorConstraintBody, LPSolver.EQ, 1.0)); } LPSolver.LPResult result = LPSolver.solve(objectiveFunction, constraints, true, true); Double objectiveValue = result.getObjectiveValue(); if(hasInput) { constraints.remove(constraints.size()-1); } evaluatedResults.put(currentRecordId, objectiveValue); } return evaluatedResults; } }
DataEnvelopmentAnalysis { public AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput) { AssociativeArray evaluatedResults = new AssociativeArray(); List<LPSolver.LPConstraint> constraints = new ArrayList<>(); Integer totalColumns = null; boolean hasInput = false; for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapInput.entrySet()) { DeaRecord currentRecord = entry.getValue(); int currentColumns = currentRecord.getInput().length; boolean currentHasInput=(currentColumns > 0); currentColumns+=currentRecord.getOutput().length; if(totalColumns==null) { totalColumns=currentColumns; hasInput=currentHasInput; } else { if(totalColumns!=currentColumns) { throw new IllegalArgumentException("The input and output columns do not match in all records."); } if(hasInput!=currentHasInput) { throw new IllegalArgumentException("The input should be used in all records or in none."); } } if(hasInput==false) { constraints.add(new LPSolver.LPConstraint(currentRecord.getOutput(), LPSolver.LEQ, 1.0)); } else { double[] currentConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { currentConstraintBody[i]=conOutput[i]; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { currentConstraintBody[conOutput.length+i]=-conInput[i]; } constraints.add(new LPSolver.LPConstraint(currentConstraintBody, LPSolver.LEQ, 0.0)); } } for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapOutput.entrySet()) { Object currentRecordId = entry.getKey(); DeaRecord currentRecord = entry.getValue(); double[] objectiveFunction; if(hasInput==false) { objectiveFunction=currentRecord.getOutput(); } else { objectiveFunction = new double[totalColumns]; double[] denominatorConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { objectiveFunction[i]=conOutput[i]; denominatorConstraintBody[i]=0.0; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { objectiveFunction[conOutput.length+i]=0.0; denominatorConstraintBody[conOutput.length+i]=conInput[i]; } constraints.add(new LPSolver.LPConstraint(denominatorConstraintBody, LPSolver.EQ, 1.0)); } LPSolver.LPResult result = LPSolver.solve(objectiveFunction, constraints, true, true); Double objectiveValue = result.getObjectiveValue(); if(hasInput) { constraints.remove(constraints.size()-1); } evaluatedResults.put(currentRecordId, objectiveValue); } return evaluatedResults; }  }
DataEnvelopmentAnalysis { public AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput) { AssociativeArray evaluatedResults = new AssociativeArray(); List<LPSolver.LPConstraint> constraints = new ArrayList<>(); Integer totalColumns = null; boolean hasInput = false; for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapInput.entrySet()) { DeaRecord currentRecord = entry.getValue(); int currentColumns = currentRecord.getInput().length; boolean currentHasInput=(currentColumns > 0); currentColumns+=currentRecord.getOutput().length; if(totalColumns==null) { totalColumns=currentColumns; hasInput=currentHasInput; } else { if(totalColumns!=currentColumns) { throw new IllegalArgumentException("The input and output columns do not match in all records."); } if(hasInput!=currentHasInput) { throw new IllegalArgumentException("The input should be used in all records or in none."); } } if(hasInput==false) { constraints.add(new LPSolver.LPConstraint(currentRecord.getOutput(), LPSolver.LEQ, 1.0)); } else { double[] currentConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { currentConstraintBody[i]=conOutput[i]; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { currentConstraintBody[conOutput.length+i]=-conInput[i]; } constraints.add(new LPSolver.LPConstraint(currentConstraintBody, LPSolver.LEQ, 0.0)); } } for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapOutput.entrySet()) { Object currentRecordId = entry.getKey(); DeaRecord currentRecord = entry.getValue(); double[] objectiveFunction; if(hasInput==false) { objectiveFunction=currentRecord.getOutput(); } else { objectiveFunction = new double[totalColumns]; double[] denominatorConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { objectiveFunction[i]=conOutput[i]; denominatorConstraintBody[i]=0.0; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { objectiveFunction[conOutput.length+i]=0.0; denominatorConstraintBody[conOutput.length+i]=conInput[i]; } constraints.add(new LPSolver.LPConstraint(denominatorConstraintBody, LPSolver.EQ, 1.0)); } LPSolver.LPResult result = LPSolver.solve(objectiveFunction, constraints, true, true); Double objectiveValue = result.getObjectiveValue(); if(hasInput) { constraints.remove(constraints.size()-1); } evaluatedResults.put(currentRecordId, objectiveValue); } return evaluatedResults; }  AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput); }
DataEnvelopmentAnalysis { public AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput) { AssociativeArray evaluatedResults = new AssociativeArray(); List<LPSolver.LPConstraint> constraints = new ArrayList<>(); Integer totalColumns = null; boolean hasInput = false; for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapInput.entrySet()) { DeaRecord currentRecord = entry.getValue(); int currentColumns = currentRecord.getInput().length; boolean currentHasInput=(currentColumns > 0); currentColumns+=currentRecord.getOutput().length; if(totalColumns==null) { totalColumns=currentColumns; hasInput=currentHasInput; } else { if(totalColumns!=currentColumns) { throw new IllegalArgumentException("The input and output columns do not match in all records."); } if(hasInput!=currentHasInput) { throw new IllegalArgumentException("The input should be used in all records or in none."); } } if(hasInput==false) { constraints.add(new LPSolver.LPConstraint(currentRecord.getOutput(), LPSolver.LEQ, 1.0)); } else { double[] currentConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { currentConstraintBody[i]=conOutput[i]; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { currentConstraintBody[conOutput.length+i]=-conInput[i]; } constraints.add(new LPSolver.LPConstraint(currentConstraintBody, LPSolver.LEQ, 0.0)); } } for(Map.Entry<Object, DeaRecord> entry : id2DeaRecordMapOutput.entrySet()) { Object currentRecordId = entry.getKey(); DeaRecord currentRecord = entry.getValue(); double[] objectiveFunction; if(hasInput==false) { objectiveFunction=currentRecord.getOutput(); } else { objectiveFunction = new double[totalColumns]; double[] denominatorConstraintBody = new double[totalColumns]; double[] conOutput=currentRecord.getOutput(); for(int i=0;i<conOutput.length;++i) { objectiveFunction[i]=conOutput[i]; denominatorConstraintBody[i]=0.0; } double[] conInput=currentRecord.getInput(); for(int i=0;i<conInput.length;++i) { objectiveFunction[conOutput.length+i]=0.0; denominatorConstraintBody[conOutput.length+i]=conInput[i]; } constraints.add(new LPSolver.LPConstraint(denominatorConstraintBody, LPSolver.EQ, 1.0)); } LPSolver.LPResult result = LPSolver.solve(objectiveFunction, constraints, true, true); Double objectiveValue = result.getObjectiveValue(); if(hasInput) { constraints.remove(constraints.size()-1); } evaluatedResults.put(currentRecordId, objectiveValue); } return evaluatedResults; }  AssociativeArray estimateEfficiency(Map<Object, DeaRecord> id2DeaRecordMapInput, Map<Object, DeaRecord> id2DeaRecordMapOutput);  }