我运行的是matsin-libs-master里contribs的emission板块的代码,根据输入数据文件生成config文件。完整代码如下:(*开头是注释)
* project: org.matsim.*
* copyright : (C) 2014 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
package org.matsim.contrib.emissions.example;
import org.matsim.contrib.emissions.utils.EmissionsConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigWriter;
import org.matsim.core.config.groups.*;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ActivityParams;
import org.matsim.core.config.groups.StrategyConfigGroup.StrategySettings;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.MatsimServices;
* Creates a config file
* with necessary emission input files for the {@link EmissionsConfigGroup EmissionsConfigGroup}.
*
* This config file is used by the {@link RunDetailedEmissionToolOfflineExample OfflineExample} and
* the {@link RunDetailedEmissionToolOnlineExample OnlineExample}
*
* @author benjamin, julia
*
* @deprecated -- has not been maintained and should in consequence be phased out. kai, nov'21
@Deprecated // has not been maintained and should in consequence be phased out. kai, nov'21
public final class CreateEmissionConfig {
private static final String inputPath = "E:/Eclipse/workspaceB/matsim-libs-master/contribs/emissions/test/input/org/matsim/contrib/emissions/z_lx/1";
private static final String networkFile = //inputPath +
"sample_network.xml";
private static final String plansFile = //inputPath +
"sample_population.xml";
private static final String emissionVehicleFile = //inputPath +
"sample_emissionVehicles.xml";
private static final String roadTypeMappingFile = //inputPath +
"sample_roadTypeMapping.txt";
private static final String averageFleetWarmEmissionFactorsFile = //inputPath +
"sample_EFA_HOT_vehcat_2005average.txt";
private static final String averageFleetColdEmissionFactorsFile = //inputPath +
"sample_EFA_ColdStart_vehcat_2005average.txt";
private static final boolean isUsingDetailedEmissionCalculation = true;
private static final String detailedWarmEmissionFactorsFile = //inputPath +
"sample_EFA_HOT_SubSegm_2005detailed.txt";
private static final String detailedColdEmissionFactorsFile = //inputPath +
"sample_EFA_ColdStart_SubSegm_2005detailed.txt";
private static final String outputPath = "E:/Eclipse/workspaceB/matsim-libs-master/contribs/emissions/test/output/";
private static final String configFilePath = inputPath + "config_v2.xml";
private static final int numberOfIterations = 6;
public static void main(String[] args) {
Config config = new Config();
config.addCoreModules();
MatsimServices controler = new Controler(config);
// controlerConfigGroup
ControlerConfigGroup ccg = controler.getConfig().controler();
ccg.setOutputDirectory(outputPath);
ccg.setFirstIteration(0);
ccg.setLastIteration(numberOfIterations-1);
// planCalcScoreConfigGroup
PlanCalcScoreConfigGroup pcs = controler.getConfig().planCalcScore();
ActivityParams homeP = new ActivityParams("home");
homeP.setTypicalDuration(12 * 3600);
pcs.addActivityParams(homeP);
ActivityParams workP = new ActivityParams("work");
workP.setTypicalDuration(8 * 3600);
pcs.addActivityParams(workP);
// strategy
StrategyConfigGroup scg = controler.getConfig().strategy();
StrategySettings strategySettings = new StrategySettings();
strategySettings.setStrategyName("ChangeExpBeta");
strategySettings.setWeight(1.0);
scg.addStrategySettings(strategySettings);
// network
NetworkConfigGroup ncg = controler.getConfig().network();
ncg.setInputFile(networkFile);
// plans
PlansConfigGroup pcg = controler.getConfig().plans();
pcg.setInputFile(plansFile);
// define emission tool input files
EmissionsConfigGroup ecg = new EmissionsConfigGroup() ;
controler.getConfig().addModule(ecg);
// one can now directly set the hbefa road types as link attributes
ecg.setEmissionRoadTypeMappingFile(roadTypeMappingFile);
ecg.setHbefaRoadTypeSource(EmissionsConfigGroup.HbefaRoadTypeSource.fromFile);
// emission vehicles are now set in the default vehicle container
config.vehicles().setVehiclesFile(emissionVehicleFile);
if ( (Boolean) false ==null ) {
ecg.setHbefaVehicleDescriptionSource( EmissionsConfigGroup.HbefaVehicleDescriptionSource.asEngineInformationAttributes );
} else if ( false ) {
ecg.setHbefaVehicleDescriptionSource( EmissionsConfigGroup.HbefaVehicleDescriptionSource.usingVehicleTypeId );
} else {
ecg.setHbefaVehicleDescriptionSource( EmissionsConfigGroup.HbefaVehicleDescriptionSource.fromVehicleTypeDescription );
}
ecg.setAverageWarmEmissionFactorsFile(averageFleetWarmEmissionFactorsFile);
ecg.setAverageColdEmissionFactorsFile(averageFleetColdEmissionFactorsFile);
// ecg.setUsingDetailedEmissionCalculation(isUsingDetailedEmissionCalculation);
ecg.setDetailedWarmEmissionFactorsFile(detailedWarmEmissionFactorsFile);
ecg.setDetailedColdEmissionFactorsFile(detailedColdEmissionFactorsFile);
ecg.setWritingEmissionsEvents(false);
ecg.setEmissionCostMultiplicationFactor(1.0);
ecg.setConsideringCO2Costs(true);
// ecg.setEmissionEfficiencyFactor(1.0);
// write config
ConfigWriter cw = new ConfigWriter(config);
cw.write(configFilePath);
}
}
以下是报错详细信息:
2022-06-05T17:24:43,263 WARN EmissionsConfigGroup:542 This property is deprecated and will be removed soon. The emission contrib expects HbefaRaodTypes to be set as link attributes explicitly
Exception in thread "main" java.lang.RuntimeException: Cost calculations are not part of the emissions contrib. Do not use this config setting.
at org.matsim.contrib.emissions.utils.EmissionsConfigGroup.setEmissionCostMultiplicationFactor(EmissionsConfigGroup.java:490)
at org.matsim.contrib.emissions.example.CreateEmissionConfig.main(CreateEmissionConfig.java:137)
初学者,不是很明白,一个“error”字眼都没看到,我以为能运行的,结果输出路径里啥也没有。是要咋弄呢。