实施例: 10个中的每个候选者得到2-偏好(比第二第一是更优选的)为3个可用作业,然后他们的老板必须最佳地分配(和均匀地分布)它们均匀地基于他们的喜好.显然,不需要的工作需要一些随机抽取.
如何编写自动计算此最佳分配的算法?
我环顾四周,找到了可能给我一些线索的二分图,但是我无法绕过它!
对于游戏的"运气"方面,我已经实现了一个简单的Fisher Yates Shuffle.
偏好权重: 如果有2个偏好,当分配给工人时,获得第一选择权重为+2,第二选择权重+1,不需要的选择-1(例如)."最优性"目标是最大化聚合偏好.
我已经将响应设置为JSON但是得到了这个
无法编写JSON:没有为类org.json.JSONObject找到序列化程序,也没有发现创建BeanSerializer的属性(为了避免异常,请禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)
@RequestMapping(value = "/customerlist", method = RequestMethod.POST)
public ResponseGenerator getCustomerList() {
ResponseGenerator responseGenerator = new ResponseGenerator();
try {
responseGenerator.setCode(StatusCode.SUCCESS.code);
responseGenerator.setMessage(StatusCode.SUCCESS.message);
responseGenerator.setStatus(ResponseStatus.SUCCESS);
JSONObject data = userService.getUserList();
responseGenerator.setJSONData(data);
return responseGenerator; //error here
} catch (Exception e) {
logger.error("Error while getting Customer List : ", e);
e.printStackTrace();
responseGenerator.setCode(StatusCode.GENERAL_ERROR.code);
responseGenerator.setMessage(StatusCode.GENERAL_ERROR.message);
responseGenerator.setStatus(ResponseStatus.FAIL);
return responseGenerator;
}
}
Run Code Online (Sandbox Code Playgroud)
userService.getUserList():
public JSONObject jsonResp;
public JSONObject getUserList() throws Exception{
jsonResp =new JSONObject();
//List<JSONObject> customers = new ArrayList<JSONObject>();
JSONObject jsonResponse = erpNextAPIClientService.getCustomerList();
//ObjectMapper objectMapper = new ObjectMapper();
//objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY); …Run Code Online (Sandbox Code Playgroud) 假设我们的数据框设置如下:
x = pd.DataFrame(np.random.randint(1, 10, 30).reshape(5,6),
columns=[f'col{i}' for i in range(6)])
x['col6'] = np.nan
x['col7'] = np.nan
col0 col1 col2 col3 col4 col5 col6 col7
0 6 5 1 5 2 4 NaN NaN
1 8 8 9 6 7 2 NaN NaN
2 8 3 9 6 6 6 NaN NaN
3 8 4 4 4 8 9 NaN NaN
4 5 3 4 3 8 7 NaN NaN
Run Code Online (Sandbox Code Playgroud)
拨打电话时x.shift(2, axis=1),col2 -> col5移动正确的,但col6并 …
我正在遍历目录中的文件并将文件详细信息存储到数组中data。如果我不尝试运行fs.stat以获取诸如文件创建/编辑日期之类的内容,则以下代码将填充数组:
fs.readdir('../src/templates', function (err, files) {
if (err) {
throw err;
}
var data = [];
files
.forEach(function (file) {
try {
fs.stat('../src/templates/'+file,(error,stats) => {
data.push({ Name : file,Path : path.join(query, file) });
});
} catch(e) {
console.log(e);
}
});
res.json(data);
});
});
Run Code Online (Sandbox Code Playgroud)
如果我将数组移到data.push(...)外面,fs.stat则返回文件数据。在fs.stat它里面返回空。我认为这是一个异步问题,因为for循环正在运行并在fs.stat运行前完成。
我想我需要在这里使用诺言,但不能确定。
我将一个实体嵌入到另一个实体中,如下所示。该存储库是在DepEntity. 我正在尝试检索在 中的列DepEntity上排序的对象。我正在使用 Pageable 进行 GET 调用并收到错误:totalExpExpEntity
2018-12-18 05:17:58.172 警告 7 --- [http-nio-8000-exec-3] .mmaExceptionHandlerExceptionResolver : 已解决 [org.springframework.data.mapping.PropertyReferenceException: 没有找到类型 DepEntity 的属性 TotalExp!]
我尝试过totalExp,exp.totalExp但exp_totalExp没有一个起作用。spring data jpa版本是2.1.1
@Entity
public class DepEntity {
@Embedded
private ExpEntity exp;
}
@Embeddable
public class ExpEntity {
@Column(name = "exp_total")
private BigDecimal totalExp;
}
Run Code Online (Sandbox Code Playgroud)
我希望结果按嵌套属性的排序顺序排列totalExp。有办法实现这一点吗?
我有一个简单的单元测试,它通过了,但在运行时抛出错误“Harness 正在尝试使用已被破坏的固定装置” ng test --watch=false。发生这种情况是因为我将组件放入吗<ng-template>?有谁知道如何解决这个错误?
describe("MenuComponent", () => {
let testHostFixture: ComponentFixture<TestHostComponent>;
let myMenuHarness: MenuHarness;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [...],
imports: [...],
providers: [...],
}).compileComponents();
})
);
beforeEach(async () => {
testHostFixture = TestBed.createComponent(TestHostComponent);
myMenuHarness = await TestbedHarnessEnvironment.harnessForFixture(
testHostFixture,
MenuHarness
);
testHostFixture.detectChanges();
});
describe("simple test", () => {
it("should pass", async () => {
await myMenuHarness.openMenu();
expect(true);
});
});
@Component({
selector: `my-test-host-component`,
template: `<kendo-grid ...>
<ng-template kendoGridColumnMenuTemplate let-service="service">
<app-my-menu [service]="service"></app-my-menu>
</ng-template>
<kendo-grid-column ... ></kendo-grid-column> …Run Code Online (Sandbox Code Playgroud) 在Ant中,我可以创建一个包含类似路径的变量的目标吗?
例如,类似于以下伪目标:
<target name="initPath">
Path = "${basedir}/../../myProject/Project/"
</target>
Run Code Online (Sandbox Code Playgroud)
其中Path是我的变量,并初始化为特定值.
我怎样才能做到这一点?
我在替换JS中的最后一个单词时遇到问题,我仍在搜索解决方案,但我无法得到它.
我有这个代码:
var string = $(element).html(); // "abc def abc xyz"
var word = "abc";
var newWord = "test";
var newV = string.replace(new RegExp(word,'m'), newWord);
Run Code Online (Sandbox Code Playgroud)
我想在此字符串中替换最后一个单词"abc",但现在我只能替换字符串中的所有或第一个匹配项.我怎样才能做到这一点?也许不是好方法?
在Python中,
re.sub('(ab)c', r'\1d', 'xxxabcxxx')
Run Code Online (Sandbox Code Playgroud)
给我回来'xxxabdxxx'.
你会期望re.sub('(ab)c', r'\0d', 'xxxabcxxx')回来 'xxxabcdxxx'.也就是说,你期望它以类似的方式工作m.group(0).
但是,这不受支持.http://bugs.python.org/issue17426#msg184210
什么是实现re.sub('(ab)c', r'\0d', 'xxxabcxxx')应该实现的简单方法,而不使用re.sub()?
我无法解决这个问题:
CREATE OR REPLACE FUNCTION dpol_insert(
dpol_cia integer, dpol_tipol character, dpol_nupol integer,
dpol_conse integer,dpol_date timestamp)
RETURNS integer AS
$BODY$
DECLARE tabla text := 'dpol'||EXTRACT (YEAR FROM $5::timestamp);
BEGIN
EXECUTE '
INSERT INTO '|| quote_ident(tabla) ||'
(dpol_cia, dpol_tipol, dpol_nupol, dpol_conse, dpol_date) VALUES ($1,$2,$3,$4,$5)
';
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Run Code Online (Sandbox Code Playgroud)
在尝试时
SELECT dpol_insert(1,'X',123456,1,'09/10/2013')
Run Code Online (Sandbox Code Playgroud)
返回下一条消息:
ERROR: there is no parameter $1
LINE 3: ...tipol, dpol_nupol, dpol_conse, dpol_date) VALUES ($1,$2,$3,$...
^
QUERY:
INSERT INTO dpol2013
(dpol_cia, dpol_tipol, dpol_nupol, dpol_conse, dpol_date) VALUES ($1,$2,$3,$4,$5) …Run Code Online (Sandbox Code Playgroud) java ×3
javascript ×3
python ×2
regex ×2
spring ×2
algorithm ×1
ant ×1
fs ×1
jasmine ×1
json ×1
kendo-grid ×1
node.js ×1
pandas ×1
plpgsql ×1
postgresql ×1
replace ×1
typescript ×1